Skip to content

Instantly share code, notes, and snippets.

@ono
Created March 1, 2012 10:23
Show Gist options
  • Select an option

  • Save ono/1948904 to your computer and use it in GitHub Desktop.

Select an option

Save ono/1948904 to your computer and use it in GitHub Desktop.
resque.sh
#!/bin/sh
usage()
{
echo "usage: ${0} {start|stop|graceful_stop|stop_child|restart} <any_process_keyword>"
exit 1
}
start_app() {
${app_cmd} 2>&1 | logger -t resque_worker &
}
stop_app() {
# TERM: Immediately kill child then exit
kill ${pid}
}
stop_child() {
# USR1: Immediately kill child but don't exit
kill -USR1 ${pid}
}
graceful_stop_app() {
# QUIT: Wait for child to finish processing then exit
kill -QUIT ${pid}
}
if [ $# -lt 2 ]; then
usage
fi
pid_file=/usr/local/app/rems3/shared/pids/resque_worker.${2}.pid
pid=`cat ${pid_file}`
app_cmd="nohup /usr/local/app/rems3/current/rails/cmd.sh rake resque:work_rems"
export PIDFILE=${pid_file}
export RAILS_ENV=production
export VERBOSE=1
export QUEUE=${3}
case $1 in
start)
start_app
;;
graceful_stop)
graceful_stop_app
;;
stop)
stop_app
;;
stopchild)
stop_child
;;
restart)
stop_app
start_app
;;
*)
usage
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment