Class: Freud::Pidfile
- Inherits:
-
Object
show all
- Includes:
- Logging
- Defined in:
- lib/freud/pidfile.rb
Instance Method Summary
collapse
Methods included from Logging
#exit, log_to, logger, #logger
Constructor Details
#initialize(path) ⇒ Pidfile
Returns a new instance of Pidfile.
7
8
9
|
# File 'lib/freud/pidfile.rb', line 7
def initialize(path)
@path = path
end
|
Instance Method Details
#==(other) ⇒ Object
27
28
29
|
# File 'lib/freud/pidfile.rb', line 27
def ==(other)
File.expand_path(to_s) == File.expand_path(other.to_s)
end
|
#kill(signal) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/freud/pidfile.rb', line 31
def kill(signal)
pid = read
return(self) unless pid
Process.kill(signal, pid)
self
end
|
#read ⇒ Object
16
17
18
19
20
21
|
# File 'lib/freud/pidfile.rb', line 16
def read
return unless @path
return unless (File.exists?(@path) and File.readable?(@path))
output = File.read(@path)
output ? output.to_i : nil
end
|
#running? ⇒ Boolean
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/freud/pidfile.rb', line 38
def running?
begin
kill(0)
true
rescue Errno::ESRCH
false
rescue Errno::EPERM
true
end
end
|
#to_s ⇒ Object
23
24
25
|
# File 'lib/freud/pidfile.rb', line 23
def to_s
@path
end
|
#write(pid) ⇒ Object
11
12
13
14
|
# File 'lib/freud/pidfile.rb', line 11
def write(pid)
File.open(@path, "w") { |f| f.write(pid.to_s) }
self
end
|