I use cron job to monitor and restart other services if they are not running. But how to monitor/restart crond itself?
2 Answers
You will either need an init system (runit
, systemd
, etc.) that can keep tabs on the process and (with appropriate configuration) restarts the daemon after failure, or to run some other daemon that checks whether the cron process is running and if not restarts it (monit
, any configuration management that runs a local agent such as CFEngine, etc.).
It's good to watch the watchers with a watchdog script of endless loop, and put that into /etc/rc.local or similar start-up file.
#!/bin/bash
for service in crond httpd whatever
do
if [ `pgrep $service` = '' ]
then
service $service restart
# OR
# systemctl restart service
fi
sleep 3
done
Of course this simple example only works if service process and service startup script share the same name. but you can fix it to match you demands