ry / ebb fork watch download tarball
public this repo is viewable by everyone
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
fixed ebb_rails stopping

thanks to a patch from Michal Rybak
i'd love to be able to offload this daemonizing buisness to a gem if there 
existed such a thing. daemons seems too heavy and not really what i need.
Ryan Dahl (author)
2 months ago
commit  b938ce438686fab63851b0d2b5752ab066b4f305
tree    cc57d49a3a3507a00c1cf1134e82ee44a76aa603
parent  9b05bbd9644cc6bbdd4f845196a715f21d91fbb2
...
35
36
37
38
 
 
 
 
 
39
40
41
...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
 
 
 
 
 
 
 
75
 
 
 
76
77
78
79
 
 
 
 
80
81
82
83
84
85
86
 
87
88
89
90
 
91
92
93
...
35
36
37
 
38
39
40
41
42
43
44
45
...
64
65
66
 
 
 
 
 
 
 
 
 
 
 
 
67
68
69
70
71
72
73
74
75
76
77
78
79
 
 
 
80
81
82
83
84
 
 
 
 
85
 
86
87
88
89
 
90
91
92
93
0
@@ -35,7 +35,11 @@ end
0
 # * killing the process gracefully
0
 module Daemonizable
0
   attr_accessor :pid_file, :log_file, :timeout
0
-
0
+
0
+ def self.included(base)
0
+ base.extend(ClassMethods)
0
+ end
0
+
0
   def pid
0
     File.exist?(pid_file) ? open(pid_file).read : nil
0
   end
0
@@ -60,34 +64,30 @@ module Daemonizable
0
     end
0
   end
0
   
0
- # Kill the process which PID is stored in +pid_file+.
0
- def self.kill(pid_file, timeout=60)
0
- if pid = open(pid_file).read
0
- pid = pid.to_i
0
- print "Sending INT signal to process #{pid} ... "
0
- begin
0
- Process.kill('INT', pid)
0
- Timeout.timeout(timeout) do
0
- sleep 0.1 while Process.running?(pid)
0
- end
0
- rescue Timeout::Error
0
- print "timeout, Sending KILL signal ... "
0
+ module ClassMethods
0
+ # Kill the process which PID is stored in +pid_file+.
0
+ def kill(pid_file, timeout=60)
0
+ raise ArgumentError, 'You must specify a pid_file to stop deamonized server' unless pid_file
0
+
0
+ if pid = File.read(pid_file)
0
+ pid = pid.to_i
0
+
0
         Process.kill('KILL', pid)
0
+ puts "stopped!"
0
+ else
0
+ puts "Can't stop process, no PID found in #{@pid_file}"
0
       end
0
- puts "stopped!"
0
- else
0
- puts "Can't stop process, no PID found in #{@pid_file}"
0
+ rescue Errno::ESRCH # No such process
0
+ puts "process not found!"
0
+ ensure
0
+ File.delete(pid_file) rescue nil
0
     end
0
- rescue Errno::ESRCH # No such process
0
- puts "process not found!"
0
- ensure
0
- File.delete(pid_file) rescue nil
0
   end
0
-
0
+
0
   private
0
   
0
   def remove_pid_file
0
- File.delete(@pid_file) if @pid_file && File.exists?(@pid_file)
0
+ File.delete(@pid_file) if @pid_file && File.exists?(@pid_file) && Process.pid == File.read(@pid_file)
0
   end
0
   
0
   def write_pid_file

Comments

    No one has commented yet.