Exception: Daemonizr::ClusterAlreadyRunningException

Inherits:
Exception
  • Object
show all
Defined in:
lib/daemonizr.rb

Overview

def pid_file(cluster, id)

if @pid_path
  f = @pid_path.strip
  f += File::SEPARATOR unless f[-1,1] == File::SEPARATOR
  f += "#{@name}-#{cluster}-#{id}.pid"
else
  nil
end

end

def write_pid_file(name, id)

pf = pid_file(name, id)
if pf
  log :debug, "Writing PID to #{pf}"
  FileUtils.mkdir_p File.dirname(pf)
  open(pf,"w") { |f| f.write(Process.pid) }
  File.chmod(0644, pf)
end

end

def remove_stale_pid_file(name, id)

pf = pid_file(name, id)
if File.exist?(pf)
  pid = File.open(pf).read
  File.delete(pf) unless pid && process_running?(pid)
end

end

def process_running?(pid)

begin
  Process.kill(0, pid.to_i)
  true
rescue Errno::ESRCH
  false
end

end