Created
March 5, 2009 00:28
-
-
Save adelcambre/74110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/merb-core/lib/merb-core/bootloader.rb b/merb-core/lib/merb-core/bootloader.rb | |
index 40037e7..7eb0e0f 100644 | |
--- a/merb-core/lib/merb-core/bootloader.rb | |
+++ b/merb-core/lib/merb-core/bootloader.rb | |
@@ -628,10 +628,12 @@ class Merb::BootLoader::LoadClasses < Merb::BootLoader | |
if Merb::Config[:fork_for_class_load] && !Merb.testing? | |
start_transaction | |
else | |
- Merb.trap('INT') do | |
+ terminate_action = Proc.new do | |
Merb.logger.warn! "Reaping Workers" | |
reap_workers | |
end | |
+ Merb.trap('INT', &terminate_action) | |
+ Merb.trap('TERM', &terminate_action) | |
end | |
# Load application file if it exists - for flat applications | |
@@ -767,9 +769,11 @@ class Merb::BootLoader::LoadClasses < Merb::BootLoader | |
Merb::Server.add_irb_trap | |
at_exit { reap_workers } | |
else | |
- Merb.trap('INT') do | |
+ terminate_action = Proc.new do | |
Merb::BootLoader.before_worker_shutdown_callbacks.each { |cb| cb.call } | |
end | |
+ Merb.trap('INT', &terminate_action) | |
+ Merb.trap('TERM', &terminate_action) | |
Merb.trap('ABRT') { reap_workers } | |
Merb.trap('HUP') { reap_workers(128, "ABRT") } | |
end | |
diff --git a/merb-core/lib/merb-core/rack/adapter/abstract.rb b/merb-core/lib/merb-core/rack/adapter/abstract.rb | |
index 49d2dff..3015794 100644 | |
--- a/merb-core/lib/merb-core/rack/adapter/abstract.rb | |
+++ b/merb-core/lib/merb-core/rack/adapter/abstract.rb | |
@@ -218,12 +218,14 @@ module Merb | |
# we let the master process' ctrl-c control the cluster | |
# of workers. | |
if Merb::Config[:daemonize] | |
- Merb.trap('INT') do | |
+ terminate_action = Proc.new do | |
Merb.exiting = true | |
stop | |
Merb.logger.warn! "Exiting port #{port}\n" | |
exit_process | |
end | |
+ Merb.trap('INT', &terminate_action) | |
+ Merb.trap('TERM', &terminate_action) | |
# If it was not fork_for_class_load, we already set up | |
# ctrl-c handlers in the master thread. | |
elsif Merb::Config[:fork_for_class_load] | |
diff --git a/merb-core/lib/merb-core/server.rb b/merb-core/lib/merb-core/server.rb | |
index 9d215f6..f21d21b 100644 | |
--- a/merb-core/lib/merb-core/server.rb | |
+++ b/merb-core/lib/merb-core/server.rb | |
@@ -85,7 +85,7 @@ module Merb | |
# If you pass "all" as the port, the signal will be sent to all Merb processes. | |
# | |
# :api: private | |
- def kill(port, sig = "INT") | |
+ def kill(port, sig = "TERM") | |
if sig.is_a?(Integer) | |
sig = Signal.list.invert[sig] | |
end | |
@@ -97,7 +97,7 @@ module Merb | |
# If a graceful exit is requested then send INT to the master process. | |
# | |
# Otherwise read pids from pid files and try to kill each process in turn. | |
- kill_pid(sig, pid_file("main")) if sig == "INT" | |
+ kill_pid(sig, pid_file("main")) if sig == "INT" || sig == "TERM" | |
else | |
kill_pid(sig, pid_file(port)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment