Skip to content

Instantly share code, notes, and snippets.

@semipermeable
Created August 1, 2011 04:14
Show Gist options
  • Save semipermeable/1117564 to your computer and use it in GitHub Desktop.
Save semipermeable/1117564 to your computer and use it in GitHub Desktop.
Sys-V init script for delayed job that plays well with capistrano and rvm
#! /bin/sh
### BEGIN INIT INFO
# Provides: delayed_job
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
### END INIT INFO
N=/etc/init.d/delayed_job
ruby=1.9.2-p180@deploy_gemset
app_root=/var/www/app/current/
user=rails
service="delayed_job"
set -e
usage() {
echo "Usage: $N {start|stop|status|restart|force-reload} <environment>" >&2
exit 1
}
set -e
[ -n "$2" ] || usage
rails_env="$2"
interact() {
op="$1"
echo "$1ing $service"
su - -c "cd $app_root && /usr/bin/env RAILS_ENV=$rails_env rvm $ruby exec bundle exec script/delayed_job $op" $user
}
case "$1" in
start|stop|status)
interact "$1"
;;
reload|restart|force-reload)
interact restart
;;
*)
usage
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment