class Application::Watcher
Constants
- APP_NAME
- LOG_FILE_PATH
Public Class Methods
daemons_run_proc_with_cleanup(options, &block)
click to toggle source
# File lib/cantemo/portal/agent/cli/commands/watch_folders.rb, line 175 def self.daemons_run_proc_with_cleanup(options, &block) options[:dir_mode] = :normal options[:dir] = File.split(__FILE__)[0] if block_given? options[:mode] = :proc options[:proc] = block end controller = Daemons::Controller.new(options, ARGV) _command, _controller_part, _app_part = controller.class.split_argv(ARGV) controller_group = Daemons::ApplicationGroup.new(controller.app_name, controller.options) controller_group.controller_argv = _controller_part controller_group.app_argv = _app_part controller_group.setup applications = controller_group.applications is_running = applications.find { |a| a.running? } if !applications.empty? puts "Found #{applications.length} existing pid file(s) #{applications.map { |a| a.pid.pid }}" should_zap_all = !is_running || (applications.length == 1 && applications.first.pid.pid == 0) if should_zap_all warn "Found stale pid file(s)" controller_group.zap_all controller_group.options[:force] = true # controller_group.applications = [] controller.options[:force] = true end end Daemons.run_proc(options[:app_name], options, &block) # controller.catch_exceptions do # controller.run # end end
run(args)
click to toggle source
# File lib/cantemo/portal/agent/cli/commands/watch_folders.rb, line 171 def self.run(args) WATCH_FOLDER_MANAGER_CLASS.run(args) end
run_in_foreground(args, options = { })
click to toggle source
# File lib/cantemo/portal/agent/cli/commands/watch_folders.rb, line 228 def self.run_in_foreground(args, options = { }) self.run(args) end
run_with_process_manager(args, options = {})
click to toggle source
# File lib/cantemo/portal/agent/cli/commands/watch_folders.rb, line 215 def self.run_with_process_manager(args, options = {}) # ARGV.unshift 'run' unless %w(start stop restart run zap killall status).include? ARGV.first require 'daemons' proc = Proc.new { self.run(args) } app_name = APP_NAME # options[:app_name] = app_name # daemons_run_proc_with_cleanup(options, &proc) # options[:force] = true Daemons.run_proc(app_name, options, &proc) end
Public Instance Methods
service_init()
click to toggle source
# File lib/cantemo/portal/agent/cli/commands/watch_folders.rb, line 114 def service_init @process_thread = nil end
service_main(*args)
click to toggle source
# File lib/cantemo/portal/agent/cli/commands/watch_folders.rb, line 118 def service_main(*args) msg = 'service_main entered at: ' + Time.now.to_s write_log{ |f| f.puts msg f.puts "Args: " + args.join(',') } @watch_folder_manager = nil @process_thread = Thread.new(@watch_folder_manager, args) do |watch_folder_manager, args| watch_folder_manager = WATCH_FOLDER_MANAGER_CLASS.new(args) watch_folder_manager.run end while running? if state == RUNNING sleep 20 msg = 'Service is running as of: ' + Time.now.to_s write_log { |f| f.puts msg } else # PAUSED or IDLE sleep 0.5 end end # We've left the loop, the daemon is about to exit. write_log{ |f| f.puts "STATE: #{state}" } msg = 'service_main left at: ' + Time.now.to_s write_log{ |f| f.puts msg } end
service_pause()
click to toggle source
# File lib/cantemo/portal/agent/cli/commands/watch_folders.rb, line 157 def service_pause @watch_folder_manager.pause end
service_resume()
click to toggle source
# File lib/cantemo/portal/agent/cli/commands/watch_folders.rb, line 161 def service_resume @watch_folder_manager.resume end
service_stop()
click to toggle source
# File lib/cantemo/portal/agent/cli/commands/watch_folders.rb, line 153 def service_stop @watch_folder_manager.stop end
write_log(message = nil) { |f| ... }
click to toggle source
# File lib/cantemo/portal/agent/cli/commands/watch_folders.rb, line 101 def write_log(message = nil, &block) if block_given? begin f = File.open(LOG_FILE_PATH, 'a') yield f ensure f.close if f && f.open? end else File.open(LOG_FILE_PATH, 'a') { |f| f.puts(message) } end end