Skip to content

Instantly share code, notes, and snippets.

@corny
Last active August 29, 2015 14:06
Show Gist options
  • Save corny/8b91311863d69b4088e6 to your computer and use it in GitHub Desktop.
Save corny/8b91311863d69b4088e6 to your computer and use it in GitHub Desktop.
Capistrano tasks for stopping Sidekiq
# lib/capistrano/tasks/sidekiq.rake
namespace :load do
task :defaults do
set :sidekiq_role, ->{ :app }
end
end
namespace :sidekiq do
def for_each_process(command)
on roles fetch(:sidekiq_role) do
execute "for file in `find '#{current_path}/tmp/pids/' -name 'sidekiq*'`; do #{command}; done || true"
end
end
# https://github.com/mperham/sidekiq/wiki/Signals
def kill_processes(signal)
unless ENV['SIDEKIQ']=='0'
for_each_process "pid=`cat $file`; echo Sending #{signal} to Sidekiq $pid; kill -#{signal} $pid"
end
end
desc "Term sidekiq"
task :stop do
kill_processes :TERM
end
desc "Quiet sidekiq (stop accepting new work)"
task :quiet do
kill_processes :USR1
end
after 'deploy:starting', 'sidekiq:quiet'
after 'deploy:publishing', 'sidekiq:stop'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment