Tuesday, November 1, 2011

A very simple watchdog

I was looking for a convenient way to check periodically whether a process is running and if not, to fire it up. This is what I came with:

[sourcecode language="bash"]

#!/bin/bash
if ps -ef | grep -v grep | grep spagobi2 ; then
exit 0
else
cd /usr/local/alterno/servidor/spagobi2/bin/
./startup.sh
exit 0
fi

[/sourcecode]

http://stackoverflow.com/questions/2366693/run-cron-job-only-if-it-isnt-already-running

This script is executed every five minutes through a cronjob with something like this:

[sourcecode language="bash"]

# MIN HOUR DAYOFMONTH MONTH DAYOFWEEK COMMAND

*/5 * * * * /root/watchSpagobi.sh

[/sourcecode]

http://www.foogazi.com/2008/04/01/quickzi-how-to-set-cron-to-run-every-5-minutes/

I don't like to run things as root, but that's not something for me to decide in this particular case.

There's yet another alternative to achieve this in a fancier way, using monit

http://linux.die.net/man/1/monit

I'll try it the next time.

No comments:

Post a Comment