class Daemons::Monitor

Public Class Methods

find(dir, app_name) click to toggle source
# File lib/daemons/monitor.rb, line 8
def self.find(dir, app_name)
  pid = PidFile.find_files(dir, app_name, false)[0]
  
  if pid
    pid = PidFile.existing(pid)
    
    unless PidFile.running?(pid.pid)
      begin; pid.cleanup; rescue ::Exception; end
      return
    end
    
    monitor = self.allocate
  
    monitor.instance_variable_set(:@pid, pid)
    
    return monitor
  end
  
  return nil
end
new(an_app) click to toggle source
# File lib/daemons/monitor.rb, line 30
def initialize(an_app)
  @app = an_app
  @app_name = an_app.group.app_name + '_monitor'
  
  if an_app.pidfile_dir
    @pid = PidFile.new(an_app.pidfile_dir, @app_name, false)
  else
    @pid = PidMem.new
  end
end

Public Instance Methods

start(applications) click to toggle source
# File lib/daemons/monitor.rb, line 107
def start(applications)
  return if applications.empty?
  
  if @pid.kind_of?(PidFile)
    start_with_pidfile(applications)
  else
    start_without_pidfile(applications)
  end
end
stop() click to toggle source
# File lib/daemons/monitor.rb, line 118
def stop
  begin; Process.kill(Application::SIGNAL, @pid.pid); rescue ::Exception; end
  
  # We try to remove the pid-files by ourselves, in case the application
  # didn't clean it up.
  begin; @pid.cleanup; rescue ::Exception; end
end