class Sidekiq::Ctl
Constants
- CMD
- DEFAULT_KILL_TIMEOUT
Attributes
kill_timeout[R]
pidfile[R]
stage[R]
Public Class Methods
new(stage, pidfile, timeout)
click to toggle source
# File lib/sidekiq/ctl.rb, line 32 def initialize(stage, pidfile, timeout) @stage = stage @pidfile = pidfile @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 command: #{stage}", :error end end
print_usage()
click to toggle source
# File lib/sidekiq/ctl.rb, line 12 def self.print_usage puts "#{CMD} - control Sidekiq from the command line." puts puts "Usage: #{CMD} quiet <pidfile> <kill_timeout>" puts " #{CMD} stop <pidfile> <kill_timeout>" puts " #{CMD} status <section>" puts puts " <pidfile> is path to a pidfile" 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 " <section> (optional) view a specific section of the status output" puts " Valid sections are: #{Sidekiqctl::Status::VALID_SECTIONS.join(', ')}" 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
Public Instance Methods
done(msg, error = nil)
click to toggle source
# File lib/sidekiq/ctl.rb, line 60 def done(msg, error = nil) puts msg exit(exit_signal(error)) end
exit_signal(error)
click to toggle source
# File lib/sidekiq/ctl.rb, line 65 def exit_signal(error) (error == :error) ? 1 : 0 end
fetch_process()
click to toggle source
# File lib/sidekiq/ctl.rb, line 50 def fetch_process Process.kill(0, pid) rescue Errno::ESRCH done "Process doesn't exist", :error # We were not allowed to send a signal, but the process must have existed # when Process.kill() was called. rescue Errno::EPERM return pid end
pid()
click to toggle source
# File lib/sidekiq/ctl.rb, line 69 def pid @pid ||= File.read(pidfile).to_i end
quiet()
click to toggle source
# File lib/sidekiq/ctl.rb, line 73 def quiet `kill -TSTP #{pid}` end
stop()
click to toggle source
# File lib/sidekiq/ctl.rb, line 77 def stop `kill -TERM #{pid}` kill_timeout.times do begin Process.kill(0, pid) rescue Errno::ESRCH FileUtils.rm_f pidfile done 'Sidekiq shut down gracefully.' rescue Errno::EPERM done 'Not permitted to shut down Sidekiq.' end sleep 1 end `kill -9 #{pid}` FileUtils.rm_f pidfile done 'Sidekiq shut down forcefully.' end
Also aliased as: shutdown