Skip to content

Instantly share code, notes, and snippets.

@itsprdp
Last active August 29, 2015 14:18
Show Gist options
  • Save itsprdp/9f08c339bd6ed284f176 to your computer and use it in GitHub Desktop.
Save itsprdp/9f08c339bd6ed284f176 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
APP_DIR=<%= current_path %>
CURRENT_DIR="cd $APP_DIR"
STAGE=<%= fetch(:stage) %>
DJ_PID="$APP_DIR/tmp/pids/delayed_job.pid"
check_pid(){
if [ -f $DJ_PID ]; then
PID=`cat $DJ_PID`
STATUS=`ps aux | grep $PID | grep -v grep | wc -l`
else
STATUS=0
PID=0
fi
}
status() {
check_pid
if [ "$PID" -ne 0 -a "$STATUS" -ne 0 ]; then
echo "Delayed job with PID $PID is running."
else
echo "Delayed job is not running."
fi
}
case "$1" in
start)
echo -n "Starting delayed_job:"
bash -l -c "$CURRENT_DIR; RAILS_ENV=$STAGE bin/delayed_job start" >> $APP_DIR/log/delayed_job.log 2>&1
echo "Delayed job is running!"
;;
stop)
echo -n "Stopping delayed_job: "
bash -l -c "$CURRENT_DIR; RAILS_ENV=$STAGE bin/delayed_job stop" >> $APP_DIR/log/delayed_job.log 2>&1
echo "Delayed job process is terminated!"
;;
status)
status
;;
*)
echo "Usage: $APP_DIR/config/delayed_job {start|stop}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment