| Class | Daemons::Monitor |
| In: |
lib/daemons/monitor.rb
|
| Parent: | Object |
# File lib/daemons/monitor.rb, line 8
8: def self.find(dir, app_name)
9: pid = PidFile.find_files(dir, app_name, false)[0]
10:
11: if pid
12: pid = PidFile.existing(pid)
13:
14: unless PidFile.running?(pid.pid)
15: begin; pid.cleanup; rescue ::Exception; end
16: return
17: end
18:
19: monitor = self.allocate
20:
21: monitor.instance_variable_set(:@pid, pid)
22:
23: return monitor
24: end
25:
26: return nil
27: end
# File lib/daemons/monitor.rb, line 30
30: def initialize(an_app)
31: @app = an_app
32: @app_name = an_app.group.app_name + '_monitor'
33:
34: if an_app.pidfile_dir
35: @pid = PidFile.new(an_app.pidfile_dir, @app_name, false)
36: else
37: @pid = PidMem.new
38: end
39: end
# File lib/daemons/monitor.rb, line 107
107: def start(applications)
108: return if applications.empty?
109:
110: if @pid.kind_of?(PidFile)
111: start_with_pidfile(applications)
112: else
113: start_without_pidfile(applications)
114: end
115: end
# File lib/daemons/monitor.rb, line 118
118: def stop
119: begin; Process.kill(Application::SIGNAL, @pid.pid); rescue ::Exception; end
120:
121: # We try to remove the pid-files by ourselves, in case the application
122: # didn't clean it up.
123: begin; @pid.cleanup; rescue ::Exception; end
124: end