lib/daemons/monitor.rb in mlanett-daemons-1.0.13 vs lib/daemons/monitor.rb in mlanett-daemons-1.1.10.2

- old
+ new

@@ -1,6 +1,8 @@ +require 'daemons/exceptions' + module Daemons require 'daemons/daemonize' class Monitor @@ -36,33 +38,37 @@ else @pid = PidMem.new end end - def watch(applications) - sleep(30) + def watch(application_group) + sleep(5) loop do - applications.each {|a| - sleep(10) - + application_group.applications.each {|a| unless a.running? a.zap! - Process.detach(fork { a.start }) + sleep(1) - sleep(10) + Process.detach(fork { a.start(restart=true) }) + + sleep(5) + + #application_group.setup end } - sleep(30) + #sleep(5) + #application_group.setup + #sleep(30) end end private :watch - def start_with_pidfile(applications) + def start_with_pidfile(application_group) fork do Daemonize.daemonize(nil, @app_name) begin @pid.pid = Process.pid @@ -79,11 +85,11 @@ # trap('TERM') { # begin; @pid.cleanup; rescue ::Exception; end # exit # } - watch(applications) + watch(application_group) rescue ::Exception => e begin File.open(@app.logfile, 'a') {|f| f.puts Time.now f.puts e @@ -96,33 +102,35 @@ end end end private :start_with_pidfile - def start_without_pidfile(applications) - Thread.new { watch(applications) } + def start_without_pidfile(application_group) + Thread.new { watch(application_group) } end private :start_without_pidfile - def start(applications) - return if applications.empty? + def start(application_group) + return if application_group.applications.empty? if @pid.kind_of?(PidFile) - start_with_pidfile(applications) + start_with_pidfile(application_group) else - start_without_pidfile(applications) + start_without_pidfile(application_group) end end def stop begin pid = @pid.pid Process.kill(Application::SIGNAL, pid) - while Pid.running?(pid) - sleep 0.1 - end + Timeout::timeout(5, TimeoutError) { + while Pid.running?(pid) + sleep(0.1) + end + } rescue ::Exception => e puts "#{e} #{pid}" puts "deleting pid-file." end \ No newline at end of file