0
@@ -74,26 +74,23 @@ module Merb
0
- def kill(port, sig="INT")
0
+ def kill(port, sig = "INT")
0
+ sig = Signal.list.invert[sig]
0
Merb::BootLoader::BuildFramework.run
0
- if sig == 9 && port == "main"
0
- kill_pid("INT", pid_file("main"))
0
+ # assume that if we kill master,
0
+ # workers should be reaped, too
0
+ if %w(main all).include?(port)
0
Dir["#{Merb.log_path}" / "*.pid"].each do |file|
0
kill_pid(sig, pid_file(port))
0
- sig = Signal.list.invert[sig]
0
- if sig == "KILL" && port == "main"
0
- Merb.fatal! "Killed all PIDs with signal KILL"
0
- Merb.fatal! "Killed #{port} with signal #{sig}"
0
# Kills the process pointed at by the provided pid file.
0
@@ -101,25 +98,28 @@ module Merb
0
def kill_pid(sig, file)
0
pid = File.read(file).chomp.to_i
0
- Merb.logger.
warn! "Killing pid #{pid}"
0
+ Merb.logger.
fatal! "Killing pid #{pid} with #{sig}"
0
FileUtils.rm(file) if File.exist?(file)
0
- Merb.fatal! "Failed to kill PID #{pid}
: '#{sig}' is an invalid " \
0
+ Merb.fatal! "Failed to kill PID #{pid}
with #{sig}: '#{sig}' is an invalid " \
0
"or unsupported signal number."
0
- Merb.fatal! "Failed to kill PID #{pid}
: Insufficient permissions."
0
+ Merb.fatal! "Failed to kill PID #{pid}
with #{sig}: Insufficient permissions."
0
- Merb.fatal! "Failed to kill PID #{pid}
: Process is " \
0
+ Merb.fatal! "Failed to kill PID #{pid}
with #{sig}: Process is " \
0
rescue Errno::EACCES => e
0
Merb.fatal! e.message, e
0
rescue Errno::ENOENT => e
0
- Merb.fatal! "Could not find a PID file at #{file}", e
0
+ # This should not cause abnormal exit, that's why
0
+ # we do not use Merb.fatal but instead just
0
+ Merb.logger.fatal! "Could not find a PID file at #{file}. Probably process is no longer running but pid file wasn't cleaned up.", e
0
if !e.is_a?(SystemExit)
0
- Merb.fatal! "Failed to kill PID #{pid}
", e
0
+ Merb.fatal! "Failed to kill PID #{pid}
with #{sig}", e
0
@@ -156,10 +156,7 @@ module Merb
0
- Merb::BootLoader::LoadClasses.reap_workers if Merb::Config[:fork_for_class_load]
0
+ Merb.trap('TERM') { shutdown }
0
puts "Running bootloaders..." if Merb::Config[:verbose]
0
@@ -170,6 +167,13 @@ module Merb
0
# Change process user/group to those specified in Merb::Config.
0
+ def shutdown(status = 0)
0
+ # reap_workers does exit but may not be called
0
+ Merb::BootLoader::LoadClasses.reap_workers(status) if Merb::Config[:fork_for_class_load]
0
+ # that's why we exit explicitly here
0
if Merb::Config[:user] && Merb::Config[:group]
0
Merb.logger.verbose! "About to change privilege to group " \