<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -562,6 +562,7 @@ class Merb::BootLoader::LoadClasses &lt; Merb::BootLoader
       end
 
       @ran = true
+      # process name you see in ps output
       $0 = &quot;merb#{&quot; : &quot; + Merb::Config[:name] if Merb::Config[:name]} : master&quot;
 
       # Log the process configuration user defined signal 1 (SIGUSR1) is received.
@@ -604,7 +605,8 @@ class Merb::BootLoader::LoadClasses &lt; Merb::BootLoader
       Process.waitall
       # remove master process pid
       Merb::Server.remove_pid(&quot;main&quot;)
-      # terminate
+      # terminate, workers remove their own pids
+      # in on exit hook
       exit
     end
 
@@ -632,6 +634,7 @@ class Merb::BootLoader::LoadClasses &lt; Merb::BootLoader
 
       loop do
         # create two connected endpoints
+        # we use them for master/workers communication
         reader, @writer = IO.pipe
         pid = Kernel.fork
 
@@ -640,7 +643,7 @@ class Merb::BootLoader::LoadClasses &lt; Merb::BootLoader
         # writer must be closed so reader can generate EOF condition
         @writer.close
 
-        # master process stores pid to merb.mail.pid
+        # master process stores pid to merb.main.pid
         Merb::Server.store_pid(&quot;main&quot;)
 
         if Merb::Config[:console_trap]</diff>
      <filename>lib/merb-core/bootloader.rb</filename>
    </modified>
    <modified>
      <diff>@@ -52,17 +52,18 @@ module Merb
       #
       # @api private
       def alive?(port)
-        puts &quot;About to check if port #{port} is alive...&quot; if Merb::Config[:verbose]
         pidfile = pid_file(port)
-        puts &quot;Pidfile is #{pidfile}...&quot; if Merb::Config[:verbose]
-        pid = File.read(pidfile).chomp.to_i
-        puts &quot;Process id is #{pid}&quot; if Merb::Config[:verbose]
+        pid     = pid_in_file(pidfile)
         Process.kill(0, pid)
         true
       rescue Errno::ESRCH, Errno::ENOENT
         false
       rescue Errno::EACCES =&gt; e
-        Merb.fatal!(&quot;You don't have access to the PID file at #{pidfile}.&quot;, e)
+        Merb.fatal!(&quot;You don't have access to the PID file at #{pidfile}: #{e.message}&quot;)
+      end
+
+      def pid_in_file(pidfile)
+        File.read(pidfile).chomp.to_i
       end
 
       # ==== Parameters
@@ -84,9 +85,32 @@ module Merb
         Merb::BootLoader::BuildFramework.run
         # assume that if we kill master,
         # workers should be reaped, too
-        if %w(main all).include?(port)
-          Dir[&quot;#{Merb.log_path}&quot; / &quot;*.pid&quot;].each do |file|
-            kill_pid(sig, file)
+        if %w(main master all).include?(port)
+          # if graceful exit is requested,
+          # send INT to master process and
+          # it's gonna do it's job
+          #
+          # Otherwise read pids from pid files
+          # and try to kill each process in
+          # turn
+          if sig == &quot;INT&quot;
+            kill_pid(sig, pid_file(&quot;main&quot;))
+          else
+            # order is important here
+            
+            # then reap workers
+            # 
+            # there is no way to handle KILL so
+            # at_exit block does not work and
+            # processes do not clean up their
+            # pid files: lets do it ourselves
+            Dir[&quot;#{Merb.log_path}&quot; / &quot;*.pid&quot;].each do |file|
+              kill_pid(sig, file)
+              ::FileUtils.rm_rf file
+            end
+
+            # reap master
+            kill_pid(sig, pid_file(&quot;main&quot;))
           end
         else
           kill_pid(sig, pid_file(port))
@@ -97,29 +121,29 @@ module Merb
       # @api private
       def kill_pid(sig, file)
         begin
-          pid = File.read(file).chomp.to_i
+          pid = pid_in_file(file)
           Merb.logger.fatal! &quot;Killing pid #{pid} with #{sig}&quot;
           Process.kill(sig, pid)
           FileUtils.rm(file) if File.exist?(file)
         rescue Errno::EINVAL
-          Merb.fatal! &quot;Failed to kill PID #{pid} with #{sig}: '#{sig}' is an invalid &quot; \
+          Merb.logger.fatal! &quot;Failed to kill PID #{pid} with #{sig}: '#{sig}' is an invalid &quot; \
             &quot;or unsupported signal number.&quot;
         rescue Errno::EPERM
-          Merb.fatal! &quot;Failed to kill PID #{pid} with #{sig}: Insufficient permissions.&quot;
+          Merb.logger.fatal! &quot;Failed to kill PID #{pid} with #{sig}: Insufficient permissions.&quot;
         rescue Errno::ESRCH
           FileUtils.rm file
-          Merb.fatal! &quot;Failed to kill PID #{pid} with #{sig}: Process is &quot; \
+          Merb.logger.fatal! &quot;Failed to kill PID #{pid} with #{sig}: Process is &quot; \
             &quot;deceased or zombie.&quot;
         rescue Errno::EACCES =&gt; e
-          Merb.fatal! e.message, e
+          Merb.logger.fatal! e.message
         rescue Errno::ENOENT =&gt; e
           # This should not cause abnormal exit, that's why
           # we do not use Merb.fatal but instead just
           # log with max level.
-          Merb.logger.fatal! &quot;Could not find a PID file at #{file}. Probably process is no longer running but pid file wasn't cleaned up.&quot;, e
+          Merb.logger.fatal! &quot;Could not find a PID file at #{file}. Probably process is no longer running but pid file wasn't cleaned up.&quot;
         rescue Exception =&gt; e
           if !e.is_a?(SystemExit)
-            Merb.fatal! &quot;Failed to kill PID #{pid} with #{sig}&quot;, e
+            Merb.logger.fatal! &quot;Failed to kill PID #{pid.inspect} with #{sig.inspect}: #{e.message}&quot;
           end
         end
       end</diff>
      <filename>lib/merb-core/server.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2d721c48372e8aaf85b5b6c4b653b83df0402915</id>
    </parent>
  </parents>
  <author>
    <name>Michael S. Klishin</name>
    <email>michael@novemberain.com</email>
  </author>
  <url>http://github.com/wycats/merb-core/commit/20fd63f05d75d10f8a6afc54c2295da259d89f78</url>
  <id>20fd63f05d75d10f8a6afc54c2295da259d89f78</id>
  <committed-date>2008-10-11T20:58:20-07:00</committed-date>
  <authored-date>2008-10-11T20:58:20-07:00</authored-date>
  <message>(put my Frankenstein voice on) It's alive!</message>
  <tree>3a9822e7340c15f2c8eaeea43dbd864d98cd119c</tree>
  <committer>
    <name>Michael S. Klishin</name>
    <email>michael@novemberain.com</email>
  </committer>
</commit>
