I have a java process that runs continually that sometimes, for reasons I have yet to fully debug, craps out. So, I also have a cron job that looks for the process every 5 minutes and if it finds the process isn't running, it calls a script to restart it.
The problem is, sometimes, every once in a while, the check-up script gets a false negative -- it thinks the process isn't running when in fact it is. I haven't seen any consistency to when it does this. But I do need a completely foolproof way to check whether the process is running.
What I'm doing currently is this:
if ! pgrep -f '/path/to/XML2DB.jar -n' > /dev/null
then
nice -n 19 java -Xmx2024M -jar /path/to/XML2DB.jar -n > /dev/null 2>/dev/null &
echo "" | mail -s "$HOST: xml2db was found not running, is being started" support@mycompany.com
fi
Before pgrep, we were using ! ps ax | grep -v grep | grep "XML2DB.jar -n" > /dev/null
but this was also giving false positives.
Linux version is Scientific Linux SL release 3.0.9 (SL)
and LSB Version
is 1.3.
Thanks in advance!
pgrep java
? – saiarcot895 Jul 21 '15 at 20:00