Monit is a monitoring software that will monitor running services, restart if service stop responding, notify you by email.
Installing Monit on Ubuntu
apt-get install monit
Start monit
On Ubuntu, run
service monit start
Enable Web Interface
Edit /etc/monit/monitrc
vi /etc/monit/monitrc
Find
# set httpd port 2812 and # use address localhost # only accept connection from localhost # allow localhost # allow localhost to connect to the server and # allow admin:monit # require user 'admin' with password 'monit'
Replace with
set httpd port 2812 and # use address localhost # only accept connection from localhost # allow localhost # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit'
Set a password.
Restart monit with
service monit restart
Now you will be able to access monit interface with URL
http://your-server-ip:2812
Monitoring Service
To monitor service nginx, create file
vi /etc/monit/conf-available/nginx
Add following content
check process nginx with pidfile /var/run/nginx.pid start program = "/etc/init.d/nginx start" stop program = "/etc/init.d/nginx stop"
To enable monitoring, create a symlink
ln -s /etc/monit/conf-available/nginx /etc/monit/conf-enabled/nginx
Check the configuration with
monit -l
To start monitoring, run
monit start all