Files
monitor/agent/monitor-agent.service
2025-12-07 10:30:10 +08:00

38 lines
1.2 KiB
Desktop File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
[Unit]
# 服务描述
Description=Monitor Agent Service
# 依赖:网络启动后再启动该服务
After=network.target network-online.target
# 可选依赖其他服务如mysql、redis等按需添加
# Requires=mysql.service
[Service]
# 服务类型forking 对应脚本的后台启动nohup
Type=forking
# 启动命令(指向我们写的启动脚本)
ExecStart=/root/monitor/agent.sh start
# 停止命令
ExecStop=/root/monitor/agent.sh stop
# 重启命令
ExecReload=/root/monitor/agent.sh restart
# PID文件路径必须与脚本中PID_FILE一致
PIDFile=/root/monitor/agent.pid
# 运行用户建议root与脚本执行用户一致
User=root
Group=root
# 故障重启策略失败后自动重启最多重启5次
Restart=on-failure
RestartSec=3s
StartLimitInterval=30s
StartLimitBurst=5
# 日志重定向可选统一到systemd日志
StandardOutput=append:/root/monitor/agent.log
StandardError=append:/root/monitor/agent.log
# 进程退出时清理环境
KillMode=process
# 优雅停止超时时间
TimeoutStopSec=10s
[Install]
# 开机自启级别:多用户模式
WantedBy=multi-user.target