mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Update capistrano recipe to use a custom ruby script, #95
This commit is contained in:
parent
60a298a602
commit
a62c775d20
3 changed files with 47 additions and 4 deletions
43
bin/sidekiqctl
Executable file
43
bin/sidekiqctl
Executable file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'fileutils'
|
||||
|
||||
stage = ARGV[0]
|
||||
pidfile = ARGV[1]
|
||||
timeout = ARGV[2].to_i
|
||||
timeout = 10 if timeout == 0
|
||||
|
||||
def done(msg)
|
||||
puts msg
|
||||
exit(0)
|
||||
end
|
||||
|
||||
done 'No pidfile given' if !pidfile
|
||||
done 'Pidfile does not exist' if !File.exist?(pidfile)
|
||||
|
||||
pid = File.read(pidfile).to_i
|
||||
done 'Invalid pidfile content' if pid == 0
|
||||
|
||||
begin
|
||||
Process.getpgid(pid)
|
||||
rescue Errno::ESRCH
|
||||
done "Process doesn't exist"
|
||||
end
|
||||
|
||||
case stage
|
||||
when 'quiet'
|
||||
`kill -USR1 #{pid}`
|
||||
when 'stop'
|
||||
`kill -TERM #{pid}`
|
||||
timeout.times do
|
||||
begin
|
||||
Process.getpgid(pid)
|
||||
rescue Errno::ESRCH
|
||||
FileUtils.rm_f pidfile
|
||||
done 'Sidekiq shut down gracefully.'
|
||||
end
|
||||
sleep 1
|
||||
end
|
||||
`kill -9 #{pid}`
|
||||
done 'Sidekiq shut down forcefully.'
|
||||
end
|
|
@ -2,18 +2,18 @@ Capistrano::Configuration.instance.load do
|
|||
before "deploy", "sidekiq:quiet"
|
||||
after "deploy", "sidekiq:restart"
|
||||
|
||||
_cset(:sidekiq_timeout) { 5 }
|
||||
_cset(:sidekiq_timeout) { 10 }
|
||||
|
||||
namespace :sidekiq do
|
||||
|
||||
desc "Quiet sidekiq (stop accepting new work)"
|
||||
task :quiet do
|
||||
run "cd #{current_path} && kill -USR1 `cat #{current_path}/tmp/pids/sidekiq.pid`"
|
||||
run "cd #{current_path} && sidekiqctl quiet #{current_path}/tmp/pids/sidekiq.pid"
|
||||
end
|
||||
|
||||
desc "Stop sidekiq"
|
||||
task :stop do
|
||||
run "cd #{current_path} && kill `cat #{current_path}/tmp/pids/sidekiq.pid` && sleep #{fetch :sidekiq_timeout} && kill -9 `cat #{current_path}/tmp/pids/sidekiq.pid` ; rm #{current_path}/tmp/pids/sidekiq.pid"
|
||||
run "cd #{current_path} && sidekiqctl stop #{current_path}/tmp/pids/sidekiq.pid #{fetch :sidekiq_timeout}"
|
||||
end
|
||||
|
||||
desc "Start sidekiq"
|
||||
|
|
|
@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|||
gem.description = gem.summary = "Simple, efficient message processing for Ruby"
|
||||
gem.homepage = "http://mperham.github.com/sidekiq"
|
||||
|
||||
gem.executables = ['sidekiq']
|
||||
gem.executables = ['sidekiq', 'sidekiqctl']
|
||||
gem.files = `git ls-files`.split("\n")
|
||||
gem.test_files = `git ls-files -- test/*`.split("\n")
|
||||
gem.name = "sidekiq"
|
||||
|
|
Loading…
Add table
Reference in a new issue