bin/sidekiqctl in sidekiq-3.3.0 vs bin/sidekiqctl in sidekiq-3.3.1
- old
+ new
@@ -1,38 +1,44 @@
#!/usr/bin/env ruby
require 'fileutils'
class Sidekiqctl
- DEFAULT_TIMEOUT = 10
+ DEFAULT_KILL_TIMEOUT = 10
- attr_reader :stage, :pidfile, :timeout
+ attr_reader :stage, :pidfile, :kill_timeout
def self.print_usage
+ puts "#{File.basename($0)} - stop a Sidekiq process from the command line."
puts
- puts "Usage: #{File.basename($0)} <command> <pidfile> <timeout>"
- puts " where <command> is either 'quiet', 'stop' or 'shutdown'"
+ puts "Usage: #{File.basename($0)} <command> <pidfile> <kill_timeout>"
+ puts " where <command> is either 'quiet' or 'stop'"
puts " <pidfile> is path to a pidfile"
- puts " <timeout> is number of seconds to wait till Sidekiq exits (default: #{Sidekiqctl::DEFAULT_TIMEOUT})"
+ puts " <kill_timeout> is number of seconds to wait until Sidekiq exits"
+ puts " (default: #{Sidekiqctl::DEFAULT_KILL_TIMEOUT}), after which Sidekiq will be KILL'd"
puts
+ puts "Be sure to set the kill_timeout LONGER than Sidekiq's -t timeout. If you want"
+ puts "to wait 60 seconds for jobs to finish, use `sidekiq -t 60` and `sidekiqctl stop"
+ puts " path_to_pidfile 61`"
+ puts
end
def initialize(stage, pidfile, timeout)
@stage = stage
@pidfile = pidfile
- @timeout = timeout
+ @kill_timeout = timeout
done('No pidfile given', :error) if !pidfile
done("Pidfile #{pidfile} does not exist", :warn) if !File.exist?(pidfile)
done('Invalid pidfile content', :error) if pid == 0
fetch_process
begin
send(stage)
rescue NoMethodError
- done 'Invalid control command', :error
+ done "Invalid command: #{stage}", :error
end
end
def fetch_process
Process.getpgid(pid)
@@ -57,11 +63,11 @@
`kill -USR1 #{pid}`
end
def stop
`kill -TERM #{pid}`
- timeout.times do
+ kill_timeout.times do
begin
Process.getpgid(pid)
rescue Errno::ESRCH
FileUtils.rm_f pidfile
done 'Sidekiq shut down gracefully.'
@@ -70,22 +76,18 @@
end
`kill -9 #{pid}`
FileUtils.rm_f pidfile
done 'Sidekiq shut down forcefully.'
end
-
- def shutdown
- quiet
- stop
- end
+ alias_method :shutdown, :stop
end
if ARGV.length < 2
Sidekiqctl.print_usage
else
stage = ARGV[0]
pidfile = ARGV[1]
timeout = ARGV[2].to_i
- timeout = Sidekiqctl::DEFAULT_TIMEOUT if timeout == 0
+ timeout = Sidekiqctl::DEFAULT_KILL_TIMEOUT if timeout == 0
Sidekiqctl.new(stage, pidfile, timeout)
end