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

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
shutdown()
Alias for: stop
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