문제

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.

  1. The Ruby file has +x permissions.
  2. The nohup.out file is empty.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top