1. Install monit
     apt-get install monit
  2. Configuring of monit
     vi /etc/monit/monitrc

    enable following line , to view the services via http

    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'
         allow @monit           # allow users of group 'monit' to connect (rw)
         allow @users readonly  # allow users of group 'users' to connect readonly
  3. Star the services
    /etc/init.d/monit start
  4. View the monit Web Interface
  5. Add process for monit to monitor
    – add xxx.conf file at /etc/monit/conf.d
    Example for Apache, content of apache.conf added to /etc/monit/conf.d  folder :

     check process apache with pidfile /var/run/apache2/apache2.pid
     start program = "/usr/bin/service apache2 start" with timeout 60 seconds
     stop program  = "/usr/bin/service apache2 stop"

    Example of MySQL , content of mysql.conf added to /etc/monit/conf.d folder

    check process mysqld with pidfile /var/run/mysqld/mysqld.pid
    group mysql
    start program = "/usr/bin/service mysql start"
    stop program = "/usr/bin/service mysql stop"
    if failed host port 3306 then restart
    if 5 restarts within 5 cycles then timeout
  6. Restart monit , see the log at: