In this example, we are doing pretty much the same as in the Sidekiq part. Stop program “/bin/su - deploy -c ‘cd /var/www/production/current & /usr/local/rbenv/bin/rbenv exec bundle exec pumactl -S /var/www/production/shared/pids/puma.state stop’” Start program “/bin/su - deploy -c ‘cd /var/www/production/current & /usr/local/rbenv/bin/rbenv exec bundle exec puma -C /var/www/production/shared/config/puma.rb’” We use Monit to monitor and manage Puma through this config:Ĭheck process puma_production with pidfile “/var/www/production/shared/pids/puma.pid” Puma is a web server for Ruby applications.
#MONIT SET ALERT CODE#
In the code above, we tell Monit that it needs to execute the command with user “deploy” and that will start the process. This applies to Nginx or any other simple system process, but if there are some Rails application components, you need to specify how the process will start in detail. Start program = “command_to_execute_to_start_the_process” stop program = “command_to_execute_to_stop_the_process” But what will happen if you start/stop it through Monit? If you save the changes and reload Monit now, it will grab the process and tell you if it’s running or not. What we do here is tell Monit that there is a Sidekiq instance running and then specify the PID file location.Ĭheck process name_of_the_process with pidfile “location_of_the_pid_file”
If totalmem is greater than 400 MB for 2 cycles then restart if does not exist then alert Stop program = “/bin/su - deploy ‘cd /home/deploy/apps/ & bundle exec sidekiqctl stop /home/deploy/apps//tmp/pids/sidekiq-0.pid’” with timeout 90 seconds Start program = “/bin/su - deploy -c ‘cd /home/deploy/apps/ & bundle exec sidekiq -e staging -C /home/deploy/apps//config/sidekiq.yml -P /home/deploy/apps//tmp/pids/sidekiq-0.pid -L /home/deploy/apps//log/sidekiq.log -d’” with timeout 90 seconds Why? It is very flexible and enables you to do the same thing in several ways through a config file:Ĭheck process sidekiq with pidfile “/home/deploy/apps//tmp/pids/sidekiq-0.pid”
We also use Monit to control and monitor Sidekiq state. Sidekiq is a background processing framework for Ruby.
#MONIT SET ALERT HOW TO#
We will show you how to set up each of them starting from nginx. In commercial projects development, we use Monit to monitor and/or control services like Sidekiq, ElasticSearch, Redis server, Rpush, Nginx, PostgreSQL, and some others. Set mailserver some_mail_server Monit configuration and setup If the first one fails, Monit will move to the second one and so on. Further, you can specify several mail servers that will be used to deliver alerts. To enable this option you need to change few lines in the main configuration file.īy default, Monit uses local host for sending emails. If you want to always have the latest updates on the monitored processes - just enable alerts and Monit will start sending emails to a specified address should any errors occur. The port address can also be changed to a custom one if security is a top priority.
Using tlsv12 Email notification format set mail-format '`Įxit $TP monitrc or /etc/monit.d/*.monit file check program SSD-A-Health with path "/etc/monit.d/scripts/hdhealth.sh a"Ĭheck program HDD-B-Health with path "/etc/monit.d/scripts/hdhealth.After the web interface has been configured it can be accessed by this link.
This is defined at the beginning of the configuration file, for example a 30second poll is defined with:Ĭhecks with 4 cycles would therefore happen every 2 minutesĬonfiguration examples Mailserver declaration set mailserver port 587 Any occurrence of if, and, with(in), has, us(ing|e), on(ly), then, for, of in the configuration file is for human readability only and are completely ignored by Monit.Ĭhecks are usually performed in cycles. Monit utilizes a configuration syntax that makes it very easy to read essentially check WHAT followed by if THING condition THEN action format. Failure to comply will result in Monit failing to start. Note: Monit requires the /etc/monitrc file (and potentially files stored in /etc/monit.d) to have 0700 permissions.