Monit and CentOS – Solving the Error “Could not execute systemctl”

My Problem – “Error: Could not execute systemctl”

I’m using Monit 5.16 on a CentOS 7 server. Monit is monitoring some crucial services like Apache and MySQL (okay, okay, it’s MariaDB). I have a very simple service check to start with:

check process apache pidfile /var/run/httpd/httpd.pid
  start = "systemctl start httpd.service"
  stop = "systemctl stop httpd.service"
  restart = "systemctl restart httpd.service"

However, when the service stops, I receive the following error in monit’s log file:

"Error: Could not execute systemctl"

My Solution:

Super simple. So simple it’s derpy. Use an absolute path to systemctl in the service check action. So it should look like this:

check process apache pidfile /var/run/httpd/httpd.pid
  start = "/usr/bin/systemctl start httpd.service"
  stop = "/usr/bin/systemctl stop httpd.service"
  restart = "/usr/bin/systemctl restart httpd.service"

5 Comments

  1. Erik

    March 10, 2015 at 5:46 pm

    I’m not a big fan of systemd but I one of its strengths is that this type monitor exists in systemd. I still like monit, but I think you are doing things the “old” way.

    Reply

    • WesleyDavid

      March 10, 2015 at 6:41 pm

      True, but monit is a generic way to do it that will work across many init systems. Sure it’s another package, but not all my systems are systemd based. Monit (or god or bluepill, etc.) is more modular and portable when using config management tools like Chef.

      Reply

      • Drew

        September 1, 2016 at 8:04 am

        Just wanted to say thank you. This fixed me right up.

        Drew

        Reply

  2. Rehnan Carolino

    October 19, 2016 at 10:21 am

    Thanks by solution! It’s work!

    Reply

  3. Marcelo Martinez

    December 6, 2016 at 12:41 pm

    same problem, fixed with the absolute systemctl path

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow TheNubbyAdmin!

follow us in feedly

Raw RSS Feed:

Contact Me!

Want to hire me as a consultant? Have a job you think I might be interested in? Drop me a line:

Contact Me!

Subscribe via Email

Your email address is handled by Google FeedBurner and never spammed!

The Nubby Archives

Circle Me on Google+!

Photos from Flickr

Me on StackExchange

The IT Crowd Strava Group