7

I like using monit for the web interface where I can see running monitored processes. I recently upgraded a server to Ubuntu 16.04 and it is using systemd.

I have everything else running but I cannot find the right monit commands to control systemd...

I used to do /etc/init.d/process start or stop or whatever. That obivously no longer works so I tried ...

systemctl start process which didn't work either. What can I do here? My monitrc is pasted below...(old style which worked on 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"
7

This should work on 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"
1

on Ubuntu 16 or later, you can using systemctl then start or stop services:

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"
  • that does not work, I get an alert that says "Description: failed to start (exit status -1) -- Program systemctl failed: File 'systemctl' does not exist" – deltaskelta Nov 18 '16 at 6:32
  • and if I use absolute paths I get alerts that stop action was done, but in my ssh session it says it is still running and my syslog says it did nothing – deltaskelta Nov 18 '16 at 6:41
  • 3
    @deltaskelta You need to give the full path, /bin/systemctl – Sharn Jayantha Oct 15 '17 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.