Skip to content

Commit

Permalink
Handle SIGUSR1 and SIGUSR2 as special cases so Sidekiq API works in J…
Browse files Browse the repository at this point in the history
…Ruby. Fixes sidekiq#2063
  • Loading branch information
substars committed Dec 11, 2014
1 parent d0cc822 commit 23e2a2b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
22 changes: 11 additions & 11 deletions lib/sidekiq/cli.rb
Expand Up @@ -107,17 +107,6 @@ def self.banner
sss }
end

private

def print_banner
# Print logo and banner for development
if environment == 'development' && $stdout.tty?
puts "\e[#{31}m"
puts Sidekiq::CLI.banner
puts "\e[0m"
end
end

def handle_signal(sig)
Sidekiq.logger.debug "Got #{sig} signal"
case sig
Expand Down Expand Up @@ -149,6 +138,17 @@ def handle_signal(sig)
end
end

private

def print_banner
# Print logo and banner for development
if environment == 'development' && $stdout.tty?
puts "\e[#{31}m"
puts Sidekiq::CLI.banner
puts "\e[0m"
end
end

def load_celluloid
raise "Celluloid cannot be required until here, or it will break Sidekiq's daemonization" if defined?(::Celluloid) && options[:daemon]

Expand Down
9 changes: 8 additions & 1 deletion lib/sidekiq/manager.rb
Expand Up @@ -21,6 +21,7 @@ class Manager
attr_accessor :fetcher

SPIN_TIME_FOR_GRACEFUL_SHUTDOWN = 1
JVM_RESERVED_SIGNALS = ['USR1', 'USR2'] # Don't Process#kill if we get these signals via the API

def initialize(condvar, options={})
logger.debug { options.inspect }
Expand Down Expand Up @@ -159,7 +160,13 @@ def ❤(key, json)
end
end

::Process.kill(msg, $$) if msg
return unless msg

if JVM_RESERVED_SIGNALS.include?(msg)
Sidekiq::CLI.instance.handle_signal(msg)
else
::Process.kill(msg, $$)
end
rescue => e
# ignore all redis/network issues
logger.error("heartbeat: #{e.message}")
Expand Down

0 comments on commit 23e2a2b

Please sign in to comment.