Monit mysql monitoring problem with mysqld.pid missing

Monit is a nice tool, it lets you monitor daemons like apache and mysql, and not only sends you alerts when these services fail but also it automagically restarts those services. But I have always faced problem with having monit properly detect whether mysql is running or not. The default monit config file /etc/monit/monitrc has this entry for mysql:

check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

It would always say mysql is not running although it is running and it immediately stops monitoring mysql. In order for this to work, first make sure that /var/run/mysqld/mysqld.pid is there, sometimes you have only mysqld.sock not .pid. In that case, go to your mysql config file /etc/mysql/my.cnf (or /etc/my.cnf) and add the following entry


pid-file = /var/run/mysqld/mysqld.pid

Do not forget to restart mysql and monit for this to take effect.

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
To