| Class | Daemons::Pid |
| In: |
lib/daemons/pid.rb
|
| Parent: | Object |
Returns the directory that should be used to write the pid file to depending on the given mode.
Some modes may require an additionaly hint, others may determine the directory automatically.
If no valid directory is found, returns nil.
# File lib/daemons/pid.rb, line 62
62: def Pid.dir(dir_mode, dir, script)
63: # nil script parameter is allowed as long as dir_mode is not :script
64: return nil if dir_mode == :script && script.nil?
65:
66: case dir_mode
67: when :normal
68: return File.expand_path(dir)
69: when :script
70: return File.expand_path(File.join(File.dirname(script),dir))
71: when :system
72: return '/var/run'
73: else
74: raise Error.new("pid file mode '#{dir_mode}' not implemented")
75: end
76: end
# File lib/daemons/pid.rb, line 7
7: def Pid.running?(pid)
8: return false unless pid
9:
10: # Check if process is in existence
11: # The simplest way to do this is to send signal '0'
12: # (which is a single system call) that doesn't actually
13: # send a signal
14: begin
15: Process.kill(0, pid)
16: return true
17: rescue Errno::ESRCH
18: return false
19: rescue ::Exception # for example on EPERM (process exists but does not belong to us)
20: return true
21: #rescue Errno::EPERM
22: # return false
23: end
24: end