Parent

Daemons::Monitor

Public Class Methods

find(dir, app_name) click to toggle source
# File lib/daemons/monitor.rb, line 7
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 = allocate

    monitor.instance_variable_set(:@pid, pid)

    return monitor
  end

  nil
end
new(an_app) click to toggle source
# File lib/daemons/monitor.rb, line 28
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(application_group) click to toggle source
# File lib/daemons/monitor.rb, line 88
def start(application_group)
  return if application_group.applications.empty?

  if @pid.kind_of?(PidFile)
    start_with_pidfile(application_group)
  else
    start_without_pidfile(application_group)
  end
end
stop() click to toggle source
# File lib/daemons/monitor.rb, line 98
def stop
  begin
    pid = @pid.pid
    Process.kill(Application::SIGNAL, pid)
                  Timeout.timeout(5, TimeoutError) do
        while Pid.running?(pid)
          sleep(0.1)
        end
      end
  rescue ::Exception => e
    puts "exception while trying to stop monitor process #{pid}: #{e}"
    puts 'deleting pid-file.'
  end

  # We try to remove the pid-files by ourselves, in case the monitor
  # didn't clean it up.
  begin; @pid.zap; rescue ::Exception; end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.