Monit a pour fonction de “surveiller” service et/ou les ressources système et d’exécuter une ou plusieurs actions en fonction de condition. Par exemple, il peut redémarrer Nginx si celui ci ne répond plus.
Configuration de base épuré
set daemon 60
set logfile syslog facility log_daemon
# Interface web de monit
#set httpd port 2812 and
# allow login:motdepasse
include /etc/monit/conf.d/*
Configuration des services
Dans /etc/monit/conf.d/, j’y ai placé un fichier de configuration par service :
apache2
check process apache with pidfile /var/run/apache2.pid
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if children > 149 then restart
if totalmem > 4096 MB for 5 cycles then restart
if 3 restarts within 5 cycles then timeout
clamd
check process clamd with pidfile /var/run/clamav/clamd.pid
group clamav
start program = "/etc/init.d/clamav-daemon start"
stop program = "/etc/init.d/clamav-daemon stop"
if failed unixsocket /var/run/clamav/clamd.ctl then restart
if 5 restarts within 5 cycles then timeout
dovecot
check process dovecot with pidfile /var/run/dovecot/master.pid
group dovecot
start program = "/etc/init.d/dovecot start"
stop program = "/etc/init.d/dovecot stop"
if failed host 127.0.0.1 port 143 protocol imap then restart
if failed host 127.0.0.1 port 993 type tcpssl sslauto protocol imap then restart
if 5 restarts within 5 cycles then timeout
freshclam
check process freshclam with pidfile /var/run/clamav/freshclam.pid
group clamav
start program = "/etc/init.d/clamav-freshclam start"
stop program = "/etc/init.d/clamav-freshclam stop"
if 5 restarts within 5 cycles then timeout
mysql
check process mysql with pidfile /var/lib/mysql/mysql.pid
group mysql
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host localhost port 3306 then restart
if 5 restarts within 5 cycles then timeout
named
check process named with pidfile /var/run/named/named.pid
start program = "/etc/init.d/bind9 start"
stop program = "/etc/init.d/bind9 stop"
if failed host 127.0.0.1 port 53 type tcp protocol dns then restart
if failed host 127.0.0.1 port 53 type udp protocol dns then restart
if 5 restarts within 5 cycles then timeout
postfix
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 host localhost port 25 protocol smtp then restart
if 5 restarts within 5 cycles then timeout
sshd
check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/ssh start"
stop program "/etc/init.d/ssh stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout