How to set up Monit to resolve MySQL “Too many connections” error


We are using FreeBSD but it can be used at any open source systems with small modifications.

When server runs into “Too many connections” MySQL error Apache reports error code 500
When you check httpd process via Monit only Apache restarts by default.
We need to restart MySQL server too.

The basic problem is: In Monit you can add only 1 start program.

We have resolved it using a .sh file.

1.) create an .sh file – webmysqlstart.sh – which restarts MySQL server and starts Apache:

(Monit stop program will stop Apache so you don’t have to restart it… Start is OK.)

Don’t forget to Chmod the .sh file to allow – execute by group.

2.) Setup Monit to run the webmysqlstart.sh

In FreeBSD you have to run sh files (via Monit) using /bin/sh -c command.
3rd line

3.) Restart Monit and test using monit.log file.

Problem solved. Monit will restart MySQL server too when runs into a httpd error. 

www.Autoalkatreszek24.HU