Class: Daemons::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/feed_updater/vendor/daemons/monitor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(an_app) ⇒ Monitor

Returns a new instance of Monitor.



30
31
32
33
34
35
36
# File 'lib/feed_updater/vendor/daemons/monitor.rb', line 30

def initialize(an_app)
  if an_app.pidfile_dir
    @pid = PidFile.new(an_app.pidfile_dir, an_app.group.app_name + '_monitor', false)
  else
    @pid = PidMem.new
  end
end

Class Method Details

.find(dir, app_name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/feed_updater/vendor/daemons/monitor.rb', line 8

def self.find(dir, app_name)
  pid = PidFile.find_files(dir, app_name)[0]
  
  if pid
    pid = PidFile.existing(pid)
    
    unless PidFile.running?(pid.pid)
      pid.cleanup rescue nil
      return
    end
    
    monitor = self.allocate
  
    monitor.instance_variable_set(:@pid, pid)
    
    return monitor
  end
  
  return nil
end

Instance Method Details

#start(applications) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/feed_updater/vendor/daemons/monitor.rb', line 105

def start(applications)
  return if applications.empty?
  
  if @pid.kind_of?(PidFile)
    start_with_pidfile(applications)
  else
    start_without_pidfile(applications)
  end
end

#stopObject



116
117
118
119
120
121
122
# File 'lib/feed_updater/vendor/daemons/monitor.rb', line 116

def stop
  Process.kill('TERM', @pid.pid) rescue nil
  
  # We try to remove the pid-files by ourselves, in case the application
  # didn't clean it up.
  @pid.cleanup rescue nil
end