public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
get merb -k and merb -K to work (with and without `all')
wycats (author)
Sat Sep 27 13:14:16 -0700 2008
commit  67e1756c267edb27f0229e0e7f9883736868742a
tree    08412e7875ad02914fc7ffafed26f0c2461505f5
parent  eb52fcec508a458af4d2d286223960b24a2954c3
...
260
261
262
 
263
264
265
...
267
268
269
 
270
271
272
...
260
261
262
263
264
265
266
...
268
269
270
271
272
273
274
0
@@ -260,6 +260,7 @@ module Merb
0
                   "merb proceses by port number.  Use merb -K all to " \
0
                   "gracefully kill all merbs.") do |ports|
0
             options[:action] = :kill
0
+            ports = "main" if ports == "all"
0
             options[:port] = ports
0
           end
0
 
0
@@ -267,6 +268,7 @@ module Merb
0
                   "by port number. This will cause the worker to" \
0
                   "be respawned. If you want to kill ") do |port|
0
             options[:action] = :kill_9
0
+            port = "main" if port == "all"
0
             options[:port] = port
0
           end
0
 
...
71
72
73
74
75
76
77
78
79
80
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
83
84
85
 
86
87
88
89
 
90
91
 
 
92
93
 
94
95
96
 
 
 
97
98
 
 
 
99
100
101
...
186
187
188
189
190
191
192
193
194
 
 
195
196
197
...
199
200
201
202
 
203
204
205
...
71
72
73
 
 
 
 
 
 
 
 
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
 
97
98
99
 
 
100
101
 
102
103
104
 
105
106
 
 
107
108
109
110
 
111
112
113
114
115
116
...
201
202
203
 
 
 
 
 
 
204
205
206
207
208
...
210
211
212
 
213
214
215
216
0
@@ -71,31 +71,46 @@ module Merb
0
       def kill(port, sig="INT")
0
         Merb::BootLoader::BuildFramework.run
0
         begin
0
-          port = "gid" if port == "all"
0
-          pid = File.read(pid_file(port)).chomp.to_i
0
-          
0
-          kill_pid(sig, pid, pid_file(port))
0
-          kill_pid(sig, -pid, pid_file(port))
0
-        ensure
0
-          Merb.started = false
0
-          exit
0
+          if sig == 9 && port == "main"
0
+            Dir["#{Merb.log_path}" / "*.pid"].each do |file|
0
+              kill_pid(9, File.read(file).chomp.to_i, file)
0
+            end
0
+          else
0
+            pid = File.read(pid_file(port)).chomp.to_i
0
+            kill_pid(sig, pid, pid_file(port))
0
+          end
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 #{pid_file(port)}", e
0
+        end
0
+        if sig.is_a?(Integer)
0
+          sig = Signal.list.invert[sig]
0
+        end
0
+        if sig == "KILL" && port == "main"
0
+          Merb.fatal! "Killed all PIDs with signal KILL"
0
+        else
0
+          Merb.fatal! "Killed #{port} with signal #{sig}"
0
         end
0
       end
0
       
0
-      def kill_pid(sig, pid)
0
+      def kill_pid(sig, pid, file)
0
         begin
0
           Process.kill(sig, pid)
0
-          FileUtils.rm(f) if File.exist?(f)
0
-          puts "killed PID #{pid} with signal #{sig}"
0
+          FileUtils.rm(file) if File.exist?(file)
0
         rescue Errno::EINVAL
0
-          puts "Failed to kill PID #{pid}: '#{sig}' is an invalid or unsupported signal number."
0
+          Merb.fatal! "Failed to kill PID #{pid}: '#{sig}' is an invalid " \
0
+            "or unsupported signal number."
0
         rescue Errno::EPERM
0
-          puts "Failed to kill PID #{pid}: Insufficient permissions."
0
+          Merb.fatal! "Failed to kill PID #{pid}: Insufficient permissions."
0
         rescue Errno::ESRCH
0
-          puts "Failed to kill PID #{pid}: Process is deceased or zombie."
0
-          FileUtils.rm f
0
+          FileUtils.rm file
0
+          Merb.fatal! "Failed to kill PID #{pid}: Process is " \
0
+            "deceased or zombie."
0
         rescue Exception => e
0
-          puts "Failed to kill PID #{pid}: #{e.message}"
0
+          if !e.is_a?(SystemExit)
0
+            Merb.fatal! "Failed to kill PID #{pid}", e
0
+          end
0
         end        
0
       end
0
 
0
@@ -186,12 +201,8 @@ module Merb
0
         FileUtils.rm(pid_file(port)) if File.file?(pid_file(port))
0
       end
0
 
0
-      def store_gid
0
-        store_details
0
-      end
0
-      
0
-      def store_details(port = nil, type = port ? "pid" : "gid")
0
-        file = pid_file(port || type)
0
+      def store_details(port = nil)
0
+        file = pid_file(port)
0
         begin
0
           FileUtils.mkdir_p(File.dirname(file))
0
         rescue Errno::EACCES => e
0
@@ -199,7 +210,7 @@ module Merb
0
             "but you did not have access.", e
0
         end
0
         Merb.logger.warn! "Storing #{type} file to #{file}..." if Merb::Config[:verbose]
0
-        File.open(file, 'w'){ |f| f.write(Process.pid.to_s) }        
0
+        File.open(file, 'w'){ |f| f.write(Process.pid.to_s) }
0
       end
0
 
0
       # Gets the pid file for the specified port.

Comments