1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/lib/sidekiq/capistrano.rb

51 lines
2.2 KiB
Ruby
Raw Normal View History

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
_cset(:sidekiq_cmd) { "#{fetch(:bundle_cmd, "bundle")} exec sidekiq" }
_cset(:sidekiqctl_cmd) { "#{fetch(:bundle_cmd, "bundle")} exec sidekiqctl" }
_cset(:sidekiq_timeout) { 10 }
_cset(:sidekiq_role) { :app }
_cset(:sidekiq_pid) { "#{current_path}/tmp/pids/sidekiq.pid" }
_cset(:sidekiq_processes) { 1 }
2012-02-26 23:36:30 -05:00
namespace :sidekiq do
def for_each_process(&block)
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)
end
end
2012-02-26 23:36:30 -05:00
desc "Quiet sidekiq (stop accepting new work)"
task :quiet, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
for_each_process do |pid_file, idx|
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"
end
2012-02-26 23:36:30 -05:00
end
desc "Stop sidekiq"
task :stop, :roles => lambda { fetch(:sidekiq_role) }, :on_no_matching_servers => :continue do
for_each_process do |pid_file, idx|
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"
end
2012-02-26 23:36:30 -05:00
end
desc "Start sidekiq"
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")
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
end
2012-02-26 23:36:30 -05:00
end
desc "Restart sidekiq"
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