Class Daemons::Pid
In: lib/daemons/pid.rb
Parent: Object

Methods

cleanup   dir   exist?   new   pid   pid=   running?  

Public Class methods

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.

[Source]

    # File lib/daemons/pid.rb, line 60
60:     def Pid.dir(dir_mode, dir, script)
61:       # nil script parameter is allowed as long as dir_mode is not :script
62:       return nil if dir_mode == :script && script.nil?                         
63:       
64:       case dir_mode
65:         when :normal
66:           return File.expand_path(dir)
67:         when :script
68:           return File.expand_path(File.join(File.dirname(script),dir))
69:         when :system  
70:           return '/var/run'
71:         else
72:           raise Error.new("pid file mode '#{dir_mode}' not implemented")
73:       end
74:     end

Initialization method

[Source]

    # File lib/daemons/pid.rb, line 77
77:     def initialize
78:     end

[Source]

    # File lib/daemons/pid.rb, line 8
 8:     def Pid.running?(pid)
 9:       # Check if process is in existence
10:       # The simplest way to do this is to send signal '0'
11:       # (which is a single system call) that doesn't actually
12:       # send a signal
13:       begin
14:         Process.kill(0, pid)
15:         return true
16:       rescue Errno::ESRCH
17:         return false
18:       rescue ::Exception   # for example on EPERM (process exists but does not belong to us)
19:         return true
20:       #rescue Errno::EPERM
21:       #  return false
22:       end
23:     end

Public Instance methods

Cleanup method

[Source]

    # File lib/daemons/pid.rb, line 90
90:     def cleanup
91:     end

Exists? method

[Source]

    # File lib/daemons/pid.rb, line 94
94:     def exist?
95:       true
96:     end

Get method

[Source]

    # File lib/daemons/pid.rb, line 82
82:     def pid
83:     end

Set method

[Source]

    # File lib/daemons/pid.rb, line 86
86:     def pid=(p)
87:     end

[Validate]