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

Methods

cleanup   dir   exist?   new   pid   pid=   running?   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 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

Initialization method

[Source]

    # File lib/daemons/pid.rb, line 79
79:     def initialize
80:     end

[Source]

    # 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

Public Instance methods

Cleanup method

[Source]

    # File lib/daemons/pid.rb, line 97
97:     def cleanup
98:     end

Exist? method

[Source]

     # File lib/daemons/pid.rb, line 101
101:     def exist?
102:       true
103:     end

Get method

[Source]

    # File lib/daemons/pid.rb, line 84
84:     def pid
85:     end

Set method

[Source]

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

Check whether the process is running

[Source]

    # File lib/daemons/pid.rb, line 92
92:     def running?
93:       return Pid.running?(pid())
94:     end

[Validate]