Skip to content

Instantly share code, notes, and snippets.

@tcocca
Created March 17, 2011 13:30
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcocca/874303 to your computer and use it in GitHub Desktop.
Save tcocca/874303 to your computer and use it in GitHub Desktop.
Monit script for multiple delayed_job workers
check process sequoia_dj2_delayed_job_0
with pidfile /home/deploy/rails/sequoia/shared/pids/delayed_job.0.pid
start program = "/home/deploy/rails/sequoia/shared/delayed_job_runner.sh start production 0"
as uid deploy and gid deploy
stop program = "/home/deploy/rails/sequoia/shared/delayed_job_runner.sh stop production 0"
as uid deploy and gid deploy
check process sequoia_dj2_delayed_job_1
with pidfile /home/deploy/rails/sequoia/shared/pids/delayed_job.1.pid
start program = "/home/deploy/rails/sequoia/shared/delayed_job_runner.sh start production 1"
as uid deploy and gid deploy
stop program = "/home/deploy/rails/sequoia/shared/delayed_job_runner.sh stop production 1"
as uid deploy and gid deploy
#!/bin/bash
export PATH="/opt/ruby-enterprise/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
APP_NAME=sequoia
APP_DIR=/home/deploy/rails
RAILS_ROOT=$APP_DIR/$APP_NAME/current
if [ "$3" ]; then
RUNNER="$3"
else
RUNNER=1
fi
ENVIRONMENT=$2
PID_FILE=$RAILS_ROOT/tmp/pids/delayed_job.$RUNNER.pid
LOG_FILE=$APP_DIR/$APP_NAME/shared/delayed_job_pid_monit.$RUNNER.log
exec 2>&1
exec 1>>$LOG_FILE
echo "Runner: $RUNNER"
echo "Env: $ENVIRONMENT"
echo "Pid: $PID_FILE"
cd $RAILS_ROOT
echo "Received $1"
function stop {
RAILS_ENV=$ENVIRONMENT $RAILS_ROOT/script/delayed_job stop -i $RUNNER
}
function start {
if [ -f $PID_FILE ]; then
echo "Pid Found. Deleting PID FILE: $PID_FILE"
rm -f $PID_FILE
fi
CMD="/usr/bin/env RAILS_ENV=$ENVIRONMENT $RAILS_ROOT/script/delayed_job start -i $RUNNER"
echo $CMD
exec $CMD
}
case $1 in
start)
stop
start
;;
stop)
stop
;;
*)
echo "WTF"
;;
esac
@Sjeanpierre
Copy link

Do you have issues with really slow start times for delayed jobs? How often is your monit config set to check on it?

@emiellohr
Copy link

Hi! I used this solution.

check process delayed_job_0
  with pidfile /u/apps/ticketing_production/shared/pids/delayed_job.0.pid
  start program = "/bin/su - avayo -c '/u/apps/ticketing_production/current/script/delayed_job start -i 0'"
  stop program = "/bin/su - avayo -c '/u/apps/ticketing_production/current/script/delayed_job stop -i 0'"

check process delayed_job_1
  with pidfile /u/apps/ticketing_production/shared/pids/delayed_job.1.pid
  start program = "/bin/su - avayo -c '/u/apps/ticketing_production/current/script/delayed_job start -i 1'"
  stop program = "/bin/su - avayo -c '/u/apps/ticketing_production/current/script/delayed_job stop -i 1'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment