Links

   Quran Explorer - Interactive Audio Recitations & Translations

Friday, June 7, 2013

Periodicaly restart dead process in Linux



The following is (one way of ) how to automaticaly check for and restart a dead process running in a linux host

Part A

/bin/netstat -ln | /bin/grep ":80 " | /usr/bin/wc -l | /bin/awk '{if ($1 == 0) system("/sbin/service httpd restart") }'

This checks if there is any service running on port 80, if not it runs the command to start the service (apache httpd in this example)

Part B
Create a cron job to periodicaly do the above

#monitors the service every 10 minutes
*/10 * * * * /usr/sesame/bash/service_monitor.sh> /dev/null 2>&1


NB: please note the trailing space after the port number


Tested in Redhat|Fedora|CentOS

No comments:

Post a Comment

Feel free to leave a comment