Skip to content

Instantly share code, notes, and snippets.

@thekindofme
Forked from semipermeable/delayed_job
Created November 22, 2011 02:55
Show Gist options
  • Save thekindofme/1384765 to your computer and use it in GitHub Desktop.
Save thekindofme/1384765 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.2p0
app_root=/home/deployer/inoty
user=deployer
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"
rails_env=PRODUCTION
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