2012-02-26 23:36:30 -05:00
|
|
|
Capistrano::Configuration.instance.load do
|
2012-08-19 14:31:20 -04:00
|
|
|
before "deploy:update_code", "sidekiq:quiet"
|
2012-04-16 21:56:41 -04:00
|
|
|
after "deploy:stop", "sidekiq:stop"
|
|
|
|
after "deploy:start", "sidekiq:start"
|
2013-01-18 12:45:28 -05:00
|
|
|
before "deploy:restart", "sidekiq:restart"
|
2012-02-26 23:36:30 -05:00
|
|
|
|
2012-12-03 16:22:37 -05:00
|
|
|
_cset(:sidekiq_cmd) { "#{fetch(:bundle_cmd, "bundle")} exec sidekiq" }
|
|
|
|
_cset(:sidekiqctl_cmd) { "#{fetch(:bundle_cmd, "bundle")} exec sidekiqctl" }
|
2012-09-11 16:26:12 -04:00
|
|
|
_cset(:sidekiq_timeout) { 10 }
|
|
|
|
_cset(:sidekiq_role) { :app }
|
|
|
|
_cset(:sidekiq_pid) { "#{current_path}/tmp/pids/sidekiq.pid" }
|
|
|
|
_cset(:sidekiq_processes) { 1 }
|
2012-03-08 23:58:51 -05:00
|
|
|
|
2012-02-26 23:36:30 -05:00
|
|
|
namespace :sidekiq do
|
2012-09-11 16:26:12 -04:00
|
|
|
def for_each_process(&block)
|
2013-01-08 16:12:44 -05:00
|
|
|
fetch(:sidekiq_processes).times do |idx|
|
2013-01-15 16:17:22 -05:00
|
|
|
yield((idx == 0 ? "#{fetch(:sidekiq_pid)}" : "#{fetch(:sidekiq_pid)}-#{idx}"), idx)
|
2012-09-11 16:26:12 -04:00
|
|
|
end
|
|
|
|
end
|
2012-02-26 23:36:30 -05:00
|
|
|
|
2012-03-08 23:58:51 -05:00
|
|
|
desc "Quiet sidekiq (stop accepting new work)"
|
2012-04-20 13:12:21 -04:00
|
|
|
task :quiet, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
2013-01-08 16:12:44 -05:00
|
|
|
for_each_process do |pid_file, idx|
|
2013-01-24 17:15:30 -05:00
|
|
|
run "if [ -d #{current_path} ] && [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then cd #{current_path} && #{fetch(:sidekiqctl_cmd)} quiet #{pid_file} ; else echo 'Sidekiq is not running'; fi"
|
2012-09-11 16:26:12 -04:00
|
|
|
end
|
2012-02-26 23:36:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Stop sidekiq"
|
2012-04-20 13:12:21 -04:00
|
|
|
task :stop, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
2013-01-08 16:12:44 -05:00
|
|
|
for_each_process do |pid_file, idx|
|
2013-01-24 17:15:30 -05:00
|
|
|
run "if [ -d #{current_path} ] && [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then cd #{current_path} && #{fetch(:sidekiqctl_cmd)} stop #{pid_file} #{fetch :sidekiq_timeout} ; else echo 'Sidekiq is not running'; fi"
|
2012-09-11 16:26:12 -04:00
|
|
|
end
|
2012-02-26 23:36:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Start sidekiq"
|
2012-04-20 13:12:21 -04:00
|
|
|
task :start, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
2012-02-26 23:36:30 -05:00
|
|
|
rails_env = fetch(:rails_env, "production")
|
2013-01-08 16:12:44 -05:00
|
|
|
for_each_process do |pid_file, idx|
|
2013-02-08 16:22:00 -05:00
|
|
|
run "cd #{current_path} ; #{fetch(:sidekiq_cmd)} -d -e #{rails_env} -C #{current_path}/config/sidekiq.yml -i #{idx} -P #{pid_file} -L #{current_path}/log/sidekiq.log", :pty => false
|
2012-09-11 16:26:12 -04:00
|
|
|
end
|
2012-02-26 23:36:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Restart sidekiq"
|
2012-04-20 13:12:21 -04:00
|
|
|
task :restart, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
|
2012-02-26 23:36:30 -05:00
|
|
|
stop
|
|
|
|
start
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|