Loading...

Service Dependencies in Monit

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Monit allows start, stop and restart program instructions in process checks. If you restart with monit, no alarm or warning is triggered then. For instance you need to restart an application like logstash for configuration changes.

We have for example this control file

CHECK PROCESS logstash WITH MATCHING "logstash/runner.rb -f /etc/logstash\s"
  start program = "/usr/bin/sudo /opt/logstash start" as uid "logstash" and gid "logstash"
  stop program = "/usr/bin/sudo /opt/logstash stop" as uid "logstash" and gid "logstash"
  if failed port 5400 type tcpssl then alert
      alert mapper-king@cinhtau.net but not on { action, instance }
  GROUP logstash

To restart the application without monit alert. If you restart logstash otherwise, it will generate an alert, since monit monitors it. :wink:

sudo monit restart logstash

You can access the start and stop instructions in other sections, if they depend on the process. For instance stop logstash if the condition is given. You can also use restart, which will just use stop and start.

CHECK PROCESS logstash WITH MATCHING "logstash/runner.rb -f /etc/logstash\s"
  start program = "/usr/bin/sudo /opt/logstash start" as uid "logstash" and gid "logstash"
  stop program = "/usr/bin/sudo /opt/logstash stop" as uid "logstash" and gid "logstash"
  depends on logstash_logfile
  if failed port 5400 type tcpssl then alert
      alert mapper-king@cinhtau.net but not on { action, instance }
  GROUP logstash

CHECK FILE logstash_logfile with path /var/log/logstash/logstash-plain.log  
  if match "IllegalArgumentException" for 5 times within 5 cycles then stop    
  GROUP logstash

For more information look at the official manual.