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, additional = nil) ⇒ Boolean
Instance Method Summary collapse
-
#cleanup ⇒ Object
Cleanup method.
-
#exists? ⇒ Boolean
Exists? method.
-
#initialize ⇒ Pid
constructor
Initialization method.
-
#pid ⇒ Object
Get method.
-
#pid=(p) ⇒ Object
Set method.
Constructor Details
#initialize ⇒ Pid
Initialization method
48 49 |
# File 'lib/daemons/pid.rb', line 48 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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/daemons/pid.rb', line 31 def Pid.dir(dir_mode, dir, script) # nil script parameter is allowed so 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.split(script)[0],dir)) when :system return '/var/run' else raise Error.new("pid file mode '#{dir_mode}' not implemented") end end |
.running?(pid, additional = nil) ⇒ Boolean
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/daemons/pid.rb', line 6 def Pid.running?(pid, additional = nil) match_pid = Regexp.new("^\\s*#{pid}\\s") got_match = false ps_all = IO.popen("ps -ax") ps_all.each { |psline| next unless psline =~ match_pid got_match = true got_match = false if additional and psline !~ /#{additional}/ break } ps_all.close return got_match end |
Instance Method Details
#cleanup ⇒ Object
Cleanup method
61 62 |
# File 'lib/daemons/pid.rb', line 61 def cleanup end |
#exists? ⇒ Boolean
Exists? method
65 66 67 |
# File 'lib/daemons/pid.rb', line 65 def exists? 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 |