Skip to content

Instantly share code, notes, and snippets.

@AvnerCohen
Created June 13, 2013 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AvnerCohen/5774806 to your computer and use it in GitHub Desktop.
Save AvnerCohen/5774806 to your computer and use it in GitHub Desktop.
Control Resque via BASH / Shell / Command line, the various rake tasks out there does not seem to do the job clean enough run as, added code to specifically take advantage of the already present resque.yml configuration file: ./resque_control.sh start
#!/bin/bash
echo "Executing Resque Manager."
start() {
echo -n "Starting resque..."
RAILS_ENV="$TARGET_ENV" QUEUE="v2_processing" VERBOSE="1" nohup bundle exec rake environment resque:work --trace > ./log/resque.log &
return
}
stop() {
echo -n "Shutting down resque... "
RUBY_SCRIPT="resque_config=YAML.load_file('./config/resque.yml'); puts \"#{resque_config['$TARGET_ENV']['host']}:#{resque_config['$TARGET_ENV']['port']}\""
REDIS_CON=`ruby -ryaml -e "$RUBY_SCRIPT"`
bundle exec resque list -r "$REDIS_CON" | grep `hostname`| awk -F : '{ print $2 }' | xargs kill -QUIT
return
}
TARGET_ENV=${2:-production}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart} <ENV>"
exit 1
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment