Monit is easiest to install through apt-get:
1 $ sudo apt-get install monit
Once monit downloads, you can add programs and processes to the configuration file:
1 $ sudo nano /etc/monit/monitrc
Monit can be started up with a command that then keeps it running in the background
1 $ monit
monit status displays monit’s details:
1 2 3 4 5 6 7 8 9 10 The Monit daemon 5.3.2 uptime: 1h 25m System 'myhost.mydomain.tld' status Running monitoring status Monitored load average [0.03] [0.14] [0.20] cpu 3.5%us 5.9%sy 0.0%wa memory usage 26100 kB [10.4%] swap usage 0 kB [0.0%] data collected Thu, 30 Aug 2012 18:35:00
Monit is very easy to use nearly out of the box. By default, it is set up to check that
services are running every 2 minutes and stores its log file in
These settings can be altered at the beginning of the configuration file in the set daemon and
logfile lines respectively.
Monit comes with it’s own
web server running on port
2812. To configure the web interface,
find and uncomment the section that begins with set httpd port
2812. Once the section is
uncommented, write in your server’s
IP or domain name as the address, allow anyone to
connect, and then create a monit
1 2 3 4 set httpd port 2812 use address 220.127.116.119 # only accept connection from localhost allow 0.0.0.0/0.0.0.0 # allow localhost to connect to the server and allow admin:monit # require user 'admin' with password 'monit'
Once this is configured,
monit should reload and reread the configuration file, and the web interface will be available:
1 $ monit reload
When you are done, try
http://18.104.22.1689:2812 You will see a dialog box appear in the browser.
General Monit Scripts
1 2 3 4 # /etc/monit/conf-available/sidekiq check process sidekiq_thepact_staging0 with pidfile "/home/deployer/www/staging/shared/tmp/pids/sidekiq.pid" start program = "/bin/su - deployer -c 'cd /home/deployer/www/staging/current && /usr/local/rvm/bin/rvm default do bundle exec sidekiq --config /home/deployer/www/staging/current/config/sidekiq.yml --index 0 -e staging -d'" with timeout 30 seconds stop program = "/bin/su - deployer -c 'cd /home/deployer/www/staging/current && /usr/local/rvm/bin/rvm default do bundle exec sidekiqctl stop /home/deployer/www/staging/shared/tmp/pids/sidekiq.pid'" with timeout 110 seconds group thepact-sidekiq-0
1 2 3 4 5 6 7 # /etc/monit/conf-available/pg check process postgres with pidfile /var/run/postgresql/9.5-main.pid group database start program = "/etc/init.d/postgresql start" stop program = "/etc/init.d/postgresql stop" if failed unixsocket /var/run/postgresql/.s.PGSQL.5432 protocol pgsql then restart
1 2 3 4 5 6 7 # /etc/monit/conf-available/puma check process puma with pidfile /var/www/myapp/production/shared/tmp/pids/puma.pid group www start program = "/bin/su - john -c '~/.rvm/bin/rvm default do bundle exec puma -C /var/www/myapp/production/shared/puma.rb --daemon'" stop program = "/bin/su - john -c 'pumactl stop -P /var/www/myapp/production/shared/tmp/pids/puma.pid'" restart program = "/bin/su - john -c 'pumactl restart -P /var/www/myapp/production/shared/tmp/pids/puma.pid'"
1 2 3 4 5 6 # /etc/monit/conf-available/puma check process puma with pidfile /var/www/myapp/production/shared/tmp/pids/puma.pid group www start program = "/bin/su - john -c '~/.rvm/bin/rvm default do bundle exec puma -C /var/www/myapp/production/shared/puma.rb --daemon'" stop program = "/bin/su - john -c '~/.rvm/bin/rvm default do bundle exec pumactl -S /var/www/myapp/production/shared/tmp/pids/puma.state stop'" restart program = "/bin/su - john -c '~/.rvm/bin/rvm default do bundle exec pumactl -S /var/www/myapp/production/shared/tmp/pids/puma.state restart'"
Using the scripts
Monit does not load
conf-available. You have to copy the scripts to
conf-enabled to have them executed by
Monit. So, we are going to link those files that
folder instead of copying/duplicating them. Its a good practice.
1 $ sudo ln /etc/monit/conf-available/puma /etc/monit/conf-enabled/puma
This will link the file there, same file will act as if it is there too.