I have Monit monitoring Mysql. When the machine shuts down abruptly eg a power failure, mysqld cannot be restarted unless /var/lib/mysql/mysql.sock is deleted, due to the error Another MySQL daemon already running with the same unix socket. What is the correct configuration to have Monit delete the file on bootup?

  • 2
    I think the monit command is: buy a UPS for any server at risk of sudden power loss. – ewwhite Mar 18 '14 at 17:44
  • Why did you bother? – redir_dev_nut Mar 18 '14 at 17:48
  • 1
    @redir_dev_nut Well, it is the proper answer, so there's that. – HopelessN00b Mar 18 '14 at 17:59
  • @HopelessN00b, no, the question is not about the environment, and it is clearly indicated as being an example. That comment would only address that single cause of abrupt shutdown. Further, the environment is out of my control. And further, it wasn't intended as an answer, clearly, and as indicated by the answer below. – redir_dev_nut Mar 18 '14 at 18:16

I joke that you should just buy a UPS... But protecting a server from sudden power loss is pretty easy. A basic UPS can provide that for you.

If those are not options (as I don't know the context of the environment and constraints), are you sure that you want the server and services coming up automatically following a hard crash with no manual intervention? If so...

Change the startup script in your Monit start command. For example:

check process mysqld
    with pidfile "/var/run/mysqld.pid"
    start program = "/sbin/service mysqld start"
    stop program = "/sbin/service mysqld stop"

Instead of using the mysqld start script, write a wrapper script that checks for the existence of the /var/lib/mysql/mysql.sock file.

Or maybe just have the start command be /sbin/service mysqld restart, as that runs a stop() followed by a start(). In the init script, the stop command removes the sock file.

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.