Sha256: 183338ab61c5cd87d374d0365ca0bd106c24515740a07fcf5e6acd73830dc97a
Contents?: true
Size: 1.35 KB
Versions: 3
Compression:
Stored size: 1.35 KB
Contents
#!/usr/bin/env ruby require 'fileutils' class Sidekiqctl attr_reader :stage, :pidfile, :timeout def initialize(stage, pidfile, timeout) @stage = stage @pidfile = pidfile @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 end end def fetch_process Process.getpgid(pid) rescue Errno::ESRCH done "Process doesn't exist", :error end def done(msg, error = nil) puts msg exit(exit_signal(error)) end def exit_signal(error) (error == :error) ? 1 : 0 end def pid @pid ||= File.read(pidfile).to_i end def quiet `kill -USR1 #{pid}` end def 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}` FileUtils.rm_f pidfile done 'Sidekiq shut down forcefully.' end def shutdown quiet stop end end stage = ARGV[0] pidfile = ARGV[1] timeout = ARGV[2].to_i timeout = 10 if timeout == 0 Sidekiqctl.new(stage, pidfile, timeout)
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-2.17.8 | bin/sidekiqctl |
sidekiq-2.17.7 | bin/sidekiqctl |
sidekiq-2.17.6 | bin/sidekiqctl |