I am trying to figure out why my process doesn't work if started via a script, but works fine if started by hand.
Here's the details:
script is a resque worker start script. The script location is /etc/monit/conf.d/start_resque.sh. Permissions are 755 and owned by ubuntu:ubuntu
When I run the script, the log output gets a pid and it says "starting worker ip-xx-xxx-xxx-xx:26732 (or whatever the pid is)", however when I ps aux | grep 26732, nothing is shown as running. When I run the same exact command by hand in my rails project directory, the same "starting worker" output is displayed, and the process is actually started and continues to run. One thing to note, additional output is displayed if started by hand: "nohup: ignoring input"
Another question someone might be able to help with, is why does BACKGROUND=yes not actually daemonize my worker...thus I'm resorting to nohup, which seems to work fine.
Here's my script (the command I run by hand is after the cd):
#!/bin/bash
echo "starting worker.."
workercount="$(ps aux | grep -c resque)"
currentdir="/var/www/apps/myapp/current"
logdir=$currentdir/log/resque_worker.log
pidfile=$currentdir/tmp/pids/resque_worker_$workercount.pid
cd $currentdir
nohup bundle exec rake environment resque:work RAILS_ENV=production QUEUE='*' VERBOSE=1 PIDFILE=$pidfile >> $logdir 2>&1 &
echo "started worker $workercount! view log at $logdir. view pidfile at $pidfile"
Additional notes: on Ubuntu 12.04 and am connected via ssh
while running both the script and the manual command.
pstree
to see if the child ( your background process ) was adopted by init ;)