Class: Daemons::Pid
- Inherits:
-
Object
- Object
- Daemons::Pid
- Defined in:
- lib/daemons/pid.rb
Class Method Summary collapse
-
.dir(dir_mode, dir, script) ⇒ Object
Returns the directory that should be used to write the pid file to depending on the given mode.
- .running?(pid) ⇒ Boolean
Instance Method Summary collapse
-
#cleanup ⇒ Object
Cleanup method.
-
#exist? ⇒ Boolean
Exists? method.
-
#initialize ⇒ Pid
constructor
Initialization method.
-
#pid ⇒ Object
Get method.
-
#pid=(p) ⇒ Object
Set method.
Constructor Details
#initialize ⇒ Pid
Initialization method
86 87 |
# File 'lib/daemons/pid.rb', line 86 def initialize end |
Class Method Details
.dir(dir_mode, dir, script) ⇒ 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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/daemons/pid.rb', line 69 def Pid.dir(dir_mode, dir, script) # nil script parameter is allowed as long as dir_mode is not :script return nil if dir_mode == :script && script.nil? case dir_mode when :normal return File.(dir) when :script return File.(File.join(File.dirname(script),dir)) when :system return '/var/run' else raise Error.new("pid file mode '#{dir_mode}' not implemented") end end |
.running?(pid) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/daemons/pid.rb', line 17 def Pid.running?(pid) # Check if process is in existence # The simplest way to do this is to send signal '0' # (which is a single system call) that doesn't actually # send a signal begin Process.kill(0, pid) return true rescue Errno::ESRCH return false rescue ::Exception # for example on EPERM (process exists but does not belong to us) return true #rescue Errno::EPERM # return false end end |
Instance Method Details
#cleanup ⇒ Object
Cleanup method
99 100 |
# File 'lib/daemons/pid.rb', line 99 def cleanup end |
#exist? ⇒ Boolean
Exists? method
103 104 105 |
# File 'lib/daemons/pid.rb', line 103 def exist? true end |
#pid ⇒ Object
Get method
91 92 |
# File 'lib/daemons/pid.rb', line 91 def pid end |
#pid=(p) ⇒ Object
Set method
95 96 |
# File 'lib/daemons/pid.rb', line 95 def pid=(p) end |