I am trying to write a watchdog for a Ruby application. So far, I have a cron job which is successfully calling a shell script:
#!/bin/sh
if ps -ef | grep -v grep | grep adpc.rb ; then
exit 0
else
NOW=$(date +"%m-%d-%Y"+"%T" )
echo "$NOW - CRITIC: ADPC service is down! Trying to initialize..." >> che.log
cd lib
nohup ruby adpc.rb &
exit 0
fi
This code runs correctly from command line, but I am not able to make the shell script execute the Ruby script when called from a cron job.
Please any help would be appreciated.
+x
permissions. Solution: replace bare "ruby" command with full path (which ruby output).
Thanks to all for the replies =)
This is usually caused by an incorrect environment. Check the Ruby output in the created nohup.out
file and log the stderr of nohup itself to a file.
It's frequently solved by starting the script with:
#!/bin/bash
source ~/.bash_profile
source ~/.bashrc
This will ensure that you run with bash
instead of sh
, and that any settings like PATH you've configured in your init files will be set.