diff --git a/config/deploy.rb b/config/deploy.rb index 92a5ca197..0f128c60d 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -35,9 +35,10 @@ set :deploy_via, :remote_cache require './lib/recipes/nginx' require './lib/recipes/unicorn' -require './lib/recipes/bluepill' +#require './lib/recipes/bluepill' require './lib/recipes/delayed_job' -#require './lib/recipes/resque' + +require './lib/recipes/resque' namespace :deploy do task :stub_xml_rpc do @@ -85,9 +86,9 @@ after "deploy:update_code", "deploy:migrate" after "deploy:setup", "deploy:symlink_pids" # Bluepill -after "deploy:restart", "bluepill:restart" # "bluepill:processes:restart_dj" # "bluepill:restart" -after "deploy:start", "bluepill:start" -after "deploy:stop", "bluepill:stop" +#after "deploy:restart", "bluepill:restart" # "bluepill:processes:restart_dj" # "bluepill:restart" +#after "deploy:start", "bluepill:start" +#after "deploy:stop", "bluepill:stop" # DJ after "deploy:stop", "delayed_job:stop" @@ -95,9 +96,9 @@ after "deploy:start", "delayed_job:start" after "deploy:restart", "delayed_job:restart" # Resque -#after "deploy:stop", "resque:stop" -#after "deploy:start", "resque:start" -#after "deploy:restart", "resque:restart" +after "deploy:stop", "resque:stop" +after "deploy:start", "resque:start" +after "deploy:restart", "resque:restart" after "deploy:restart", "deploy:cleanup" diff --git a/config/production.pill b/config/production.pill index 04808b266..8e36cdbce 100644 --- a/config/production.pill +++ b/config/production.pill @@ -23,6 +23,9 @@ Bluepill.application(app_name, :log_file => "/srv/rosa_build/shared/log/bluepill process.pid_file = pid_path process.stop_command = "kill -QUIT {{PID}}" process.daemonize = true + process.start_grace_time = 5.seconds + process.stop_grace_time = 5.seconds + process.restart_grace_time = 5.seconds #process.monitor_children do |c| # c.stop_command = "kill -USR1 {{PID}}" # TODO: Are we really need this? diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index 266754ec9..9b5bab974 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -1,40 +1,30 @@ -## -*- encoding : utf-8 -*- -#Capistrano::Configuration.instance(:must_exist).load do -# -# require 'resque/server' -# -# namespace :resque do -# task :start do -# start_workers -# end -# -# task :stop do -# stop_workers -# end -# -# task :restart do -# stop_workers -# start_workers -# end -# -# def rails_env -# fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : '' -# end -# -# def stop_workers -# pids = Array.new -# -# Resque.workers.each do |worker| -# pids << worker.to_s.split(/:/)[1] -# end -# -# if pids.size > 0 -# system("kill -QUIT #{pids.join(' ')}") -# end -# end -# -# def start_workers -# run "cd #{fetch :release_path} && QUEUE=* #{ rails_env } bundle exec rake resque:work &" -# end -# end -#end +# -*- encoding : utf-8 -*- +Capistrano::Configuration.instance(:must_exist).load do + + namespace :resque do + task :start do + start_workers + end + + task :stop do + stop_workers + end + + task :restart do + stop_workers + start_workers + end + + def rails_env + fetch(:rails_env, false) ? "RAILS_ENV=#{fetch(:rails_env)}" : '' + end + + def stop_workers + run "kill -QUIT `cat #{ fetch(:current_path) }/tmp/pids/resque.pid`" + end + + def start_workers + run "cd #{fetch :current_path} && QUEUE=fork_and_import #{ rails_env } BACKGROUND=yes PIDFILE=#{ fetch(:current_path) }/tmp/pids/resque.pid bundle exec rake resque:work" + end + end +end