Skip to content

Instantly share code, notes, and snippets.

@nbrew
Forked from stuzart/gist:3169625
Last active March 13, 2018 18:55
Show Gist options
  • Save nbrew/10154438 to your computer and use it in GitHub Desktop.
Save nbrew/10154438 to your computer and use it in GitHub Desktop.
Simple init script for starting group of delayed_job workers.
#!/bin/sh
# upstart-job
#
# Symlink target for initscripts that have been converted to Upstart.
set -e
APP_PATH="/srv/rails/seek"
APP_NAME="Seek"
APP_USER="www-data"
NUM_WORKERS="1"
start_job() {
echo "Starting ${APP_NAME} delayed job"
sudo -iu ${APP_USER} bash -c "cd $APP_PATH && RAILS_ENV=production ./bin/bundle exec bin/delayed_job -n #{NUM_WORKERS} start"
}
stop_job() {
echo "Stopping ${APP_NAME} delayed job"
sudo -iu ${APP_USER} bash -c "cd $APP_PATH && RAILS_ENV=production ./bin/bundle exec bin/delayed_job stop"
}
COMMAND="$1"
shift
case $COMMAND in
status)
;;
start|stop|restart)
$ECHO
if [ "$COMMAND" = "stop" ]; then
stop_job
elif [ "$COMMAND" = "start" ]; then
start_job
elif [ "$COMMAND" = "restart" ]; then
stop_job
sleep 1s
start_job
exit 0
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment