I'm trying to watch the mailing list manager sympa with monit. A running sympa instance consists of multiple processes for the different tasks of list management (e.g. a separate process for archiving emails), but all processes are started/stopped with a single init script.
Optimally, monit should alert me if any of the services fails and then restart sympa, but restart it only once. A first solution looked like this:
check process sympa
with pidfile /var/run/sympa/sympa.pid
start program = "/etc/init.d/sympa start"
stop program = "/etc/init.d/sympa stop"
check process sympa_bounced
with pidfile /var/run/sympa/bounced.pid
start program = "/etc/init.d/sympa start"
stop program = "/etc/init.d/sympa stop"
check process sympa_bulk
with pidfile /var/run/sympa/bulk.pid
start program = "/etc/init.d/sympa start"
stop program = "/etc/init.d/sympa stop"
However, if I stop sympa manually, the init script will be executed multiple times, once for every service I define (because every service failed).
My second approach was to define dependencies and only alert if any of the subservices fail:
check process sympa
with pidfile /var/run/sympa/sympa.pid
start program = "/etc/init.d/sympa start"
stop program = "/etc/init.d/sympa stop"
depends on sympa_bounced, sympa_bulk
check process sympa_bounced
with pidfile /var/run/sympa/bounced.pid
if does not exist then alert
check process sympa_bulk
with pidfile /var/run/sympa/bulk.pid
if does not exist then alert
But since the subservices are not restarted, the main service will also not be restarted. So I figured I could 'fake' a restart by setting start/stop to /bin/true
:
check process sympa
with pidfile /var/run/sympa/sympa.pid
start program = "/etc/init.d/sympa start"
stop program = "/etc/init.d/sympa stop"
depends on sympa_bounced, sympa_bulk
check process sympa_bounced
with pidfile /var/run/sympa/bounced.pid
start program = "/bin/true"
stop program = "/bin/true"
check process sympa_bulk
with pidfile /var/run/sympa/bulk.pid
start program = "/bin/true"
stop program = "/bin/true"
This does not work either, because if sympa_bulk fails, the PID file will not created before the sympa service is restarted, and this does not happen before the sympa_bulk is running again.
Is there a way to monitor such a service, get alert messages for all subservices, but restart the service only once, even if all subservices fail at once?