Created
July 7, 2009 06:13
-
-
Save jbr/141921 to your computer and use it in GitHub Desktop.
Delayed::Job runner for monit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin | |
APP_NAME=your_app_name_here #<--fill this in | |
APP_DIR=/var/www/apps/ | |
RAILS_ROOT=$APP_DIR/current | |
if [ "$3" ]; then | |
RUNNER="$3" | |
else | |
RUNNER=1 | |
fi | |
RAILS_ENV=$2 | |
PID_FILE=$RAILS_ROOT/tmp/pids/job_runner.$RUNNER.pid | |
LOG_FILE=$RAILS_ROOT/log/job_runner.$RUNNER.log | |
exec 2>&1 | |
exec 1>>$LOG_FILE | |
cd $RAILS_ROOT | |
echo "Received $1" | |
function stop { | |
echo "Checking for pid at $PID_FILE..." | |
if [ -f $PID_FILE ]; then | |
echo "Pid found. Killing `cat $PID_FILE`" | |
kill `cat $PID_FILE` 2>/dev/null; true | |
echo "Done. Removing pid file $PID_FILE" | |
rm -f $PID_FILE | |
echo "All done." | |
else | |
echo "No pid file" | |
fi | |
} | |
function start { | |
echo $$ > $PID_FILE | |
echo "Starting runner $RUNNER... ($$)" | |
CMD="$RAILS_ROOT/script/runner" | |
OPTIONS=" -e $RAILS_ENV $APP_DIR/shared/job_runner.rb" | |
echo $CMD $OPTIONS | |
exec $CMD $OPTIONS | |
} | |
case $1 in | |
start) | |
stop | |
start | |
;; | |
stop) | |
stop | |
;; | |
*) | |
echo "WTF" | |
;; | |
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
check process my_app_job_runner_1 | |
with pidfile /var/www/apps/my_app/current/tmp/pids/job_runner.1.pid | |
start program = "/var/www/apps/my_app/shared/dj_monit_runner start production 1" as uid whatever and gid whatever | |
stop program = "/var/www/apps/my_app/shared/dj_monit_runner stop production 1" as uid whatever and gid whatever | |
group my_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STDOUT.sync = true | |
STDERR.sync = true | |
Delayed::Worker.new.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment