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
Exist? method.
-
#initialize ⇒ Pid
constructor
Initialization method.
-
#pid ⇒ Object
Get method.
-
#pid=(p) ⇒ Object
Set method.
-
#running? ⇒ Boolean
Check whether the process is running.
-
#zap ⇒ Object
Zap method.
Constructor Details
#initialize ⇒ Pid
Initialization method
49 50 |
# File 'lib/daemons/pid.rb', line 49 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.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/daemons/pid.rb', line 32 def self.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 fail Error.new("pid file mode '#{dir_mode}' not implemented") end end |
.running?(pid) ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/daemons/pid.rb', line 5 def self.running?(pid) return false unless 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 TimeoutError raise rescue Errno::ESRCH return false rescue ::Exception # for example on EPERM (process exists but does not belong to us) return true end end |
Instance Method Details
#cleanup ⇒ Object
Cleanup method
66 67 |
# File 'lib/daemons/pid.rb', line 66 def cleanup end |
#exist? ⇒ Boolean
Exist? method
74 75 76 |
# File 'lib/daemons/pid.rb', line 74 def exist? true end |
#pid ⇒ Object
Get method
53 54 |
# File 'lib/daemons/pid.rb', line 53 def pid end |
#pid=(p) ⇒ Object
Set method
57 58 |
# File 'lib/daemons/pid.rb', line 57 def pid=(p) end |
#running? ⇒ Boolean
Check whether the process is running
61 62 63 |
# File 'lib/daemons/pid.rb', line 61 def running? Pid.running?(pid) end |
#zap ⇒ Object
Zap method
70 71 |
# File 'lib/daemons/pid.rb', line 70 def zap end |