It looks like you're new here. If you want to get involved, click one of these buttons!
This is a general-purpose monitoring script for any service. It will check if the service is running and restart it if it is not via cron. It can also email you when service restarts occur so you can investigate the cause.
Would love to have your input and suggestions on how to improve it.
Example usage in Crontab:
*/5 * * * * sh /root/watchdog.sh apache2
(Checks if apache is running every five minutes and restart it if it's down.)
*/5 * * * * sh /root/watchdog.sh mysqld mysql
("Loose" check for mysqld every 5 minutes, second parameter is the name of the service to restart, in case the application and service names differ.)
More examples are available at the top of the shell script.
Requirements: pgrep service