class Freud::Pidfile

Public Class Methods

new(path) click to toggle source
# File lib/freud/pidfile.rb, line 7
def initialize(path)
    @path = path
end

Public Instance Methods

==(other) click to toggle source
# File lib/freud/pidfile.rb, line 27
def ==(other)
    File.expand_path(to_s) == File.expand_path(other.to_s)
end
kill(signal) click to toggle source
# File lib/freud/pidfile.rb, line 31
def kill(signal)
    pid = read
    return(self) unless pid
    Process.kill(signal, pid)
    self
end
read() click to toggle source
# 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?() click to toggle source
# 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() click to toggle source
# File lib/freud/pidfile.rb, line 23
def to_s
    @path
end
write(pid) click to toggle source
# File lib/freud/pidfile.rb, line 11
def write(pid)
    File.open(@path, "w") { |f| f.write(pid.to_s) }
    self
end