Monit

From MattWiki
Jump to: navigation, search

Monit is an app that will keep a program running.

Prereq

yum -y install flex byacc

Download, Compile, & Install Monit

Download the lates monit source file from Monit's Download Site.

(As of the writing of this page the current version was 4.9

cd /tmp/svn
wget http://www.tildeslash.com/monit/dist/monit-4.9.tar.gz
tar -xvf monit-4.9.tar.gz

To Compile monit run

cd monit-4.9
./configure
make

You need to have root access to install monit.

sudo make install
    < or >
su -c make install

After you install monit you must make a config file.

Here's my /etc/monit.conf file

set daemon  30
set logfile /var/log/monit.log
set mailserver mail.mattrude.com
#set mailserver smtp.comcast.net
set mail-format
 { from: monit@mattrude.com }
#set alert matt@mattrude.com  # Send alert to system admin on any event
set httpd port 2812 and
    allow desktop.mattrude.com
    allow 127.0.0.1
    allow username:password     # user 'admin' with password 'monit'


check process Apache with pidfile /var/run/httpd.pid
 group mythtv
 start program = "/etc/init.d/httpd start"
 stop program  = "/etc/init.d/httpd stop"
 if failed port 80
 then restart

check process postfix with pidfile /var/spool/postfix/pid/master.pid
  group mail
  start program = "/etc/init.d/postfix start"
  stop  program = "/etc/init.d/postfix stop"
  if failed port 25 protocol smtp then restart
  if 5 restarts within 5 cycles then timeout
  depends on postfix_rc

check file postfix_rc with path /etc/init.d/postfix
  group mail
  if failed checksum then unmonitor
  if failed permission 755 then unmonitor
  if failed uid root then unmonitor
  if failed gid root then unmonitor

check process spamd with pidfile /var/run/spamd.pid
  group mail
  start program = "/etc/init.d/spamd start"
  stop  program = "/etc/init.d/spamd stop"
  if 5 restarts within 5 cycles then timeout
  if cpu usage > 99% for 5 cycles then alert
  if mem usage > 99% for 5 cycles then alert
  depends on spamd_bin
  depends on spamd_rc

check file spamd_bin with path /usr/local/bin/spamd
  group mail
  if failed checksum then unmonitor
  if failed permission 755 then unmonitor
  if failed uid root then unmonitor
  if failed gid root then unmonitor

check file spamd_rc with path /etc/init.d/spamd
  group mail
  if failed checksum then unmonitor
  if failed permission 755 then unmonitor
  if failed uid root then unmonitor
  if failed gid root then unmonitor

check process amavisd with pidfile /opt/virus/amavis-new/var/run/amavisd.pid
  group mail
  start program = "/etc/init.d/amavis-new start"
  stop  program = "/etc/init.d/amavis-new stop"
  if failed port 10024 protocol smtp then restart
  if 5 restarts within 5 cycles then timeout
  depends on amavisd_bin
  depends on amavisd_rc

check file amavisd_bin with path /opt/virus/amavis-new/bin/amavisd
  group mail
  if failed checksum then unmonitor
  if failed permission 755 then unmonitor
  if failed uid root then unmonitor
  if failed gid root then unmonitor

check file amavisd_rc with path /etc/init.d/amavis-new
  group mail
  if failed checksum then unmonitor
  if failed permission 755 then unmonitor
  if failed uid root then unmonitor
  if failed gid root then unmonitor

check process Lirc with pidfile /var/run/lircd.pid
 group mythtv
 start program = "/etc/init.d/lircd start"
 stop program  = "/etc/init.d/lircd stop"

check process Mythbackend with pidfile /var/run/mythbackend.pid
 group mythtv
 start program = "/sbin/service mythbackend restart"
 stop program  = "/sbin/service mythbackend stop"
 if failed port 6544 then restart
 depends on Mysql
 depends on Lirc

check process Mysql with pidfile /var/run/mysqld/mysqld.pid
 group mythtv
 start program = "/etc/init.d/mysqld start"
 stop program = "/etc/init.d/mysqld stop"
 if failed port 3306 then restart

check process NTP with pidfile /var/run/ntpd.pid
 group system
 start program = "/etc/init.d/ntpd start"
 stop program = "/etc/init.d/ntpd stop"
 if failed port 123 type udp then restart

check process SSH with pidfile /var/run/sshd.pid
 group system
 start program = "/etc/init.d/sshd start"
 stop program = "/etc/init.d/sshd stop"
 if failed port 22 then restart

Starting & Running Monit

To start and run monit after setting up the above config file, try:

touch /etc/monitrc
chmod 700 /etc/monitrc
chmod 700 /etc/monit.conf
echo "monit -c /etc/monit.conf" >> /etc/rc.local
monit -c /etc/monit.conf