我喜欢将 monit 用于 Web 界面,在其中我可以看到正在运行的受监控进程。我最近将服务器升级到 Ubuntu 16.04,它正在使用 systemd。
我已经运行了其他所有东西,但我找不到正确的 monit 命令来控制 systemd...
我曾经做过/etc/init.d/process start
什么stop
或者什么。这显然不再有效,所以我尝试了......
systemctl start process
这也不起作用。我在这里能做什么?我的监视器粘贴在下面...(旧样式,适用于 14.04)
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
check process sshd with pidfile /var/run/sshd.pid
start program = "etc/init.d/ssh start"
stop program = "etc/init.d/ssh stop"
答案1
这应该适用于 RHEL / CentOS 7 / Ubuntu 18.04
check process nginx with pidfile /var/run/nginx.pid
start program = "/bin/systemctl start nginx"
stop program = "/bin/systemctl stop nginx"
check process sshd with pidfile /var/run/sshd.pid
start program = "/bin/systemctl start sshd"
stop program = "/bin/systemctl stop sshd"
答案2
Monit 希望所有路径都完全合格。显然是 Monit 控制文件 (/etc/monit/monitrc)。
systemctl
在这种情况下,需要指定完全限定的路径。
在上Ubuntu 20.04 LTS
,我曾经which systemctl
找到它的完全限定路径是/usr/sbin/systemctl
。
所以,下面给出的片段对我有用。
start program = "/usr/sbin/systemctl start nginx"
stop program = "/usr/sbin/systemctl stop nginx"
答案3
在 Ubuntu 16 或更高版本上,您可以使用 systemctl 然后启动或停止服务:
check process nginx with pidfile /var/run/nginx.pid
start program = "systemctl start nginx"
stop program = "systemctl stop nginx"
check process sshd with pidfile /var/run/sshd.pid
start program = "systemctl start sshd"
stop program = "systemctl stop sshd"