0

I've installed Monit on Ubuntu server 12.04 but Im having issues getting mysql monitoring to work at all. Here is what I have done so far.

#/etc/default/monit
startup=1

#/etc/mysql/my.cnf
pid-file        = /var/run/mysqld/mysqld.pid

#/etc/monit/monitrc
set daemon 60
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group mysql
start program = "/etc/init.d/mysql start" with timeout 30 seconds
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

The mysqld.pid file is being created as expected but monit cannot access it. Here are the permissions for mysqld.pid

-rw-rw---- 1 mysql mysql 6 2014-06-02 11:36 mysqld.pid 

Here is the status for monit

#monit status
Process 'mysql'
status                            not monitored
monitoring status                 not monitored
data collected                    Mon Jun  2 23:49:37 2014

And here are the errors Im seeing in the monit log

Jun  2 23:47:07 MySQL-Dev monit[13034]: 'mysql' process is not running
Jun  2 23:47:07 MySQL-Dev monit[13034]: 'mysql' trying to restart  
Jun  2 23:47:07 MySQL-Dev monit[13034]: monit: Error opening the pidfile '/var/run/mysqld/mysqld.pid' -- Permission denied
Jun  2 23:47:07 MySQL-Dev monit[13034]: monit: Error opening the pidfile '/var/run/mysqld/mysqld.pid' -- Permission denied
Jun  2 23:47:07 MySQL-Dev monit[13034]: 'mysql' start: /etc/init.d/mysql
Jun  2 23:47:07 MySQL-Dev monit[13034]: monit: Error opening the pidfile '/var/run/mysqld/mysqld.pid' -- Permission denied
Jun  2 23:47:37 MySQL-Dev monit[13034]: last message repeated 31 times
Jun  2 23:47:37 MySQL-Dev monit[13034]: 'mysql' failed to start
Jun  2 23:48:37 MySQL-Dev monit[13034]: 'mysql' service timed out and will not be checked anymore

Im not sure what to do at this point and I have not been able to find anything online that addresses my specific issue.

Eko3alpha
  • 147
  • 1
  • 8

2 Answers2

0

Your monit process does not have permissions to access /var/run/mysqld/mysqld.pid. Try adding monit user to mysql group with gpasswd -a monit mysql (or whatever your monit user account is), restart monit and see if that helps.

Instead you might also open up the /var/run/mysqld directory and the mysql.pid file permissions for world readability or use ACLs.

Janne Pikkarainen
  • 31,454
  • 4
  • 56
  • 78
  • I looked at the users list in /etc/passwd and I don't see monit listed as one of the users, do I need to manually create a monit user? I would have thought that installing monit would provide a user for me. – Eko3alpha Jun 03 '14 at 11:09
0

If you run monit as root, it should be able to access this pid file. Please check if your not running monit with another user.

# ps -eaf | grep monit
root     XXXX     1  0 Jun20 ?        00:00:08 /usr/sbin/monit -c /etc/monit/monitrc -s /var/lib/monit/monit.state
Lucas Castro
  • 121
  • 1
  • 5
  • This was exactly the problem! I thought by using "sudo" it would run monit under root. I had to literally log in as root and then start monit. Thanks for your help! – Eko3alpha Jun 22 '14 at 18:12