Monitoring running services and restart them if they stop working on Ubuntu.
12-18-2015, 05:56 AM
(This post was last modified: 12-26-2015, 04:25 PM by pinguy.)
To monitor running services and restart them if they stop working you can use Monit.
Here is the guide to install it:
https://www.digitalocean.com/community/t...gure-monit
But for a basic install run:
My setup:
And edit:
And add this to the bottom of the file.
Here is an example of Monit restarting Apache when it went down 7hrs ago.
Here is the guide to install it:
https://www.digitalocean.com/community/t...gure-monit
But for a basic install run:
Code:
apt-get install monit
My setup:
Code:
nano /etc/monit/monitrc
And edit:
Code:
set httpd port 2812
use address 12.34.56.789 or monit.YourDomain.com # only accept connection from localhost
allow 0.0.0.0/0.0.0.0 # allow localhost to connect to the server and
allow admin:*password* # require user 'admin' with password 'monit'
And add this to the bottom of the file.
Code:
Monitor
check process apache with pidfile /var/run/apache2/apache2.pid
start program = "/etc/init.d/apache2 start" with timeout 60 seconds
stop program = "/etc/init.d/apache2 stop"
if failed host YourDomain.com port 80 protocol http then restart
Monitor
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed unixsocket /run/mysqld/mysqld.sock then restart
Code:
service monit restart
Here is an example of Monit restarting Apache when it went down 7hrs ago.