monit — утилита, которая позволяет отслеживать запущен ли процесс. Если нет — она может его перезапустить.
1) Устанавливаем из пакетов:
pkg install sysutils/monit
2) Добавляем в автозагрузку:
в файл /etc/rc.conf добавляем строку monit_enable=»YES»
3) Создаем файл настроек на основе /usr/local/etc/monitrc.sample .Можно просто переименовать в /usr/local/etc/monitrc
Из того что нужно было мне:
set daemon 30 #интервал проверки в секундах set logfile /var/log/monit.log #куда пишем логи
Веб интерфейс, как лишняя «дыра» не нужен — комментируем
#set httpd port 2812 and # use address localhost # allow localhost # allow admin:monit
include /etc/monit.d/* #откуда берем настройки по мониторингу
4) В /etc/monit.d/ создаем файл, например monit.conf с отслеживаемыми сервисами. Например:
check process shellinaboxd with pidfile /var/run/shellinaboxd.pid start program = "/usr/local/etc/rc.d/shellinaboxd start" stop program = "/bin/sh -c 'kill `cat /var/run/shellinaboxd.pid`'"
Вот пример конфига который получился в конце концов у меня:
set mailserver mail.erfwerfwer.ru USERNAME "fser@erfwer.ru" PASSWORD "й423523452345" set alert init@уцвцув.ru set mail-format {from: цувцу@цувцувцу.ru} check process mpd5 with pidfile /var/run/mpd5.pid start program = "/usr/local/etc/rc.d/mpd5 start" stop program = "/bin/sh -c 'kill `cat /var/run/mpd5.pid`'" if cpu > 60% for 2 cycles then alert if not exist then restart if not exist for 2 cycles then alert check process radiusd matching "radiusd" start program = "/usr/local/etc/rc.d/radiusd start" stop program = "/usr/bin/killall radiusd" if cpu usage > 95% for 10 cycles then restart if cpu > 60% for 2 cycles then alert if not exist then restart if not exist for 2 cycles then alert check process mysqld matching "mysqld" start program = "/usr/local/etc/rc.d/mysql-server start" stop program = "/usr/bin/killall mysqld" if cpu usage > 95% for 10 cycles then restart if cpu > 60% for 2 cycles then alert if not exist then restart if not exist for 2 cycles then alert check process db2dhcp matching "db2dhcp" start program = "/usr/local/etc/rc.d/db2dhcp.sh start" stop program = "/usr/bin/killall db2dhcp" if cpu usage > 95% for 10 cycles then restart if cpu > 60% for 2 cycles then alert if not exist then restart if not exist for 2 cycles then alert check process squid matching "squid" start program = "/usr/local/etc/rc.d/squid start" stop program = "/usr/bin/killall squid" if cpu > 60% for 2 cycles then alert if not exist then restart if not exist for 2 cycles then alert check process named matching "named" start program = "/usr/sbin/named -t /var/named -u bind" stop program = "/usr/bin/killall named" if cpu usage > 95% for 10 cycles then restart if cpu > 60% for 2 cycles then alert if not exist then restart if not exist for 2 cycles then alert check process httpd matching "httpd" start program = "/usr/local/etc/rc.d/apache22 start" stop program = "/usr/bin/killall apache22" if cpu usage > 95% for 10 cycles then restart if cpu > 60% for 2 cycles then alert if not exist then restart if not exist for 2 cycles then alert