0
# * killing the process gracefully
0
attr_accessor :pid_file, :log_file, :timeout
0
+ def self.included(base)
0
+ base.extend(ClassMethods)
0
File.exist?(pid_file) ? open(pid_file).read : nil
0
@@ -60,34 +64,30 @@ module Daemonizable
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
- print "Sending INT signal to process #{pid} ... "
0
- Process.kill('INT', pid)
0
- Timeout.timeout(timeout) do
0
- sleep 0.1 while Process.running?(pid)
0
- print "timeout, Sending KILL signal ... "
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
+ if pid = File.read(pid_file)
0
Process.kill('KILL', pid)
0
+ puts "Can't stop process, no PID found in #{@pid_file}"
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
+ File.delete(pid_file) rescue nil
0
- rescue Errno::ESRCH # No such process
0
- puts "process not found!"
0
- File.delete(pid_file) rescue nil
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)
Comments
No one has commented yet.