Skip to content

Commit

Permalink
explicitly exit(0) on SIGTERM; keep it simple and trap less signals
Browse files Browse the repository at this point in the history
Thanks to Brandon Keepers and Paul Gideon Dann for reporting that
`Process.kill :TERM, $$' does not work reliably.

For now, we will just exit(0) since that really won't do any harm.

Also, removed unnecessary traps on INT and QUIT.
  • Loading branch information
guns committed Sep 22, 2010
1 parent ef64bbe commit b947840
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/delayed/daemon_tasks.rb
Expand Up @@ -38,7 +38,7 @@
$0 = "delayed_worker.#{id}"

# reset all inherited traps from main process
[:CLD, :HUP, :TERM, :INT, :QUIT].each { |sig| trap sig, 'DEFAULT' }
[:CLD, :HUP, :TERM].each { |sig| trap sig, 'DEFAULT' }

# lay quiet for a while before booting up if specified
sleep delay if delay
Expand Down Expand Up @@ -119,21 +119,20 @@
end

# terminate children on user termination
[:TERM, :INT, :QUIT].each do |sig|
trap sig do
rails_logger.call "SIG#{sig} received! Shutting down workers."
trap :TERM do
rails_logger.call 'SIGTERM received! Shutting down workers.'

# reset trap handlers so we don't get caught in a trap loop
[:CLD, sig].each { |s| trap s, 'DEFAULT' }
# reset trap handlers so we don't get caught in a trap loop
[:CLD, :HUP, :TERM].each { |s| trap s, 'DEFAULT' }

# kill the children and reap them before terminating
Process.kill :TERM, *children.keys
Process.waitall
rails_logger.call "All workers have shut down."
# kill the children and reap them before terminating
Process.kill :TERM, *children.keys
Process.waitall
rails_logger.call 'All workers have shut down. Exiting.'

# propagate the signal like a proper process should
Process.kill sig, $$
end
# TODO: investigate why some users are reporting that
# `Process.kill :TERM, $$' isn't working
exit
end

# NOTE: We want to block on something so that Process.waitall doesn't
Expand Down

0 comments on commit b947840

Please sign in to comment.