Created
April 1, 2015 19:26
-
-
Save jdkealy/a7f817bbb8e568ff38bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#bash script to start workers | |
# Load RVM into a shell session *as a function* | |
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then | |
# First try to load from a user install | |
source "$HOME/.rvm/scripts/rvm" | |
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then | |
# Then try to load from a root install | |
source "/usr/local/rvm/scripts/rvm" | |
else | |
printf "ERROR: An RVM installation was not found.\n" | |
fi | |
# Use rvm to switch to the default ruby. | |
rvm use default | |
# Now launch the app | |
cd /srv/my_app | |
nohup bundle exec rake RAILS_ENV=qa resque:workers QUEUE='*' COUNT='1' PIDFILE=/tmp/worker_one.pid & | |
nohup bundle exec rake RAILS_ENV=qa resque:workers QUEUE='*' COUNT='1' PIDFILE=/tmp/worker_two.pid & | |
nohup bundle exec rake RAILS_ENV=qa resque:workers QUEUE='*' COUNT='1' PIDFILE=/tmp/worker_three.pid & | |
#put in a bash script to execute the following rake task in /etc/init.d and create a symlink to it in /etc/rc0.d | |
#rake task | |
namespace :resq do | |
def worker_killer(pid_files) | |
puts Resque.workers.count | |
busy_processes = [] | |
pid_files.each do |p| | |
id = File.read(p).to_i | |
Resque.workers.each do |w| | |
if w.id.ends_with? "#{id}:*" | |
if w.working? | |
busy_processes << p | |
puts busy_processes | |
else | |
w.unregister_worker | |
Process.kill(15, id) | |
end | |
end | |
end | |
end | |
if busy_processes.count > 0 | |
sleep 10 | |
worker_killer(busy_processes) | |
end | |
end | |
desc "kill servers resque workers" | |
task :kill_workers => :environment do | |
worker_killer(["/tmp/worker_one.pid", "/tmp/worker_two.pid", "/tmp/worker_three.pid"]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment