class Emque::Consuming::Pidfile

Attributes

path[RW]
pid[RW]

Public Class Methods

new(path) click to toggle source
# File lib/emque/consuming/pidfile.rb, line 12
def initialize(path)
  self.path = path
  ensure_dir_exists
  self.pid = File.read(path).to_i if File.exists?(path)
end

Public Instance Methods

running?() click to toggle source
# File lib/emque/consuming/pidfile.rb, line 18
def running?
  if pid
    if pid == 0
      rm_file
    else
      begin
        Process.getpgid(pid)
        return true
      rescue Errno::ESRCH
        rm_file
      end
    end
  end
  false
end
write() click to toggle source
# File lib/emque/consuming/pidfile.rb, line 34
def write
  File.open(path, "w") do |f|
    f.puts Process.pid
  end
end

Private Instance Methods

ensure_dir_exists() click to toggle source
# File lib/emque/consuming/pidfile.rb, line 45
def ensure_dir_exists
  FileUtils.mkdir_p(File.dirname(path))
end
rm_file() click to toggle source
# File lib/emque/consuming/pidfile.rb, line 49
def rm_file
  FileUtils.rm_f(path) if File.exists?(path)
end