Monitor Salt with Monit

December 16, 2014   

Sometimes salt has the tendency to crash. So we can use monit to fix that problem

This assumes you already have the EPEL repo installed

yum install monit

Now with monit installed we can edit the following config

/etc/monit.conf

With the following contents

set daemon 5
  with start delay 5
set logfile /var/log/monit.log
set idfile /var/lib/monit.id
set statefile /var/run/monit.state
set mailserver
  localhost port 25
  with timeout 30 seconds
set mail-format {
      from: monit@hostname.domain.com
   subject: $SERVICE $EVENT at $DATE
   message:     Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
    Yours sincerely,
    monit

}
set alert techops@manage.com
  only on { nonexist, timeout, resource, icmp, connection}
set eventqueue
  basedir /var/tmp
  slots 100
set httpd port 2812 and
  use address 0.0.0.0
  allow 0.0.0.0/0.0.0.0
  allow localhost
include /etc/monit.d/*.conf

Make sure to change the use address so it won’t mind to all ips or just se the allow subnet/mask to a valid one.

Then edit the following file

/etc/monit.d/salt.conf

It will look like this

check process salt
  with pidfile /var/run/salt-minion.pid
  group system
  start "/etc/init.d/salt-minion start"
  stop "/etc/init.d/salt-minion stop"
  if 3 restarts within 5 cycles
    then unmonitor

That should check if salt is up and running.

You can use this process for almost any process that sets a local pid to check.



comments powered by Disqus