Install Monit on Ubuntu

Monit can be used to monitor services, restart them if required. To install monit, run

apt -y install monit

To start monit, run

systemctl start monit

Monitor Apache

Advertisement

vi /etc/monit/conf-available/apache2-custom

Add

check process apache with pidfile /var/run/apache2/apache2.pid
    group www-data
    start program = "/etc/init.d/apache2 start"
    stop program  = "/etc/init.d/apache2 stop"
    if failed host localhost port 80 protocol http then restart
    if 5 restarts within 5 cycles then timeout

Activate the rule with

ln -s /etc/monit/conf-available/apache2-custom /etc/monit/conf-enabled/apache2-custom

Restart monit with

systemctl restart monit

Testing If Monit works

Open 2 terminals. On one, tail the monit logs with

tail -f /var/log/monit.log

On other terminal, stop Apache

service apache2 stop

Within 2 minutes, monit will restart apache web server.

monit

Add a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Advertisement