lib/splash/controller.rb in prometheus-splash-0.4.5 vs lib/splash/controller.rb in prometheus-splash-0.5.0

- old
+ new

@@ -10,14 +10,34 @@ include Splash::Loggers def startdaemon(options = {}) config = get_config log = get_logger + log.level = :fatal if options[:quiet] unless verify_service host: config.prometheus_pushgateway_host ,port: config.prometheus_pushgateway_port then return {:case => :service_dependence_missing, :more => 'Prometheus Gateway'} end + realpid = get_processes pattern: get_config.daemon_process_name + foreground = get_processes patterns: [ "splash", "foreground" ] + unless foreground.empty? or options[:foreground] then + return {:case => :already_exist, :more => "Splash Process already launched on foreground "} + end + unless File::exist? config.full_pid_path then + unless realpid.empty? then + return {:case => :already_exist, :more => "Splash Process already launched "} + end + if options[:purge] then + transport = get_default_client + if transport.class == Hash and transport.include? :case then + splash_exit transport + else + queue = "splash.#{Socket.gethostname}.input" + transport.purge queue: queue + log.info "Queue : #{queue} purged" + end + end daemon_config = {:description => config.daemon_process_name, :pid_file => config.full_pid_path, :stdout_trace => config.full_stdout_trace_path, :stderr_trace => config.full_stderr_trace_path, :foreground => options[:foreground] @@ -41,10 +61,12 @@ end end def stopdaemon(options = {}) config = get_config + log = get_logger + log.level = :fatal if options[:quiet] if File.exist?(config.full_pid_path) then begin pid = `cat #{config.full_pid_path}`.to_i Process.kill("TERM", pid) acase = {:case => :quiet_exit, :more => 'Splash stopped succesfully'} @@ -61,12 +83,16 @@ def statusdaemon(options = {}) log = get_logger config = get_config pid = realpid = '' pid = `cat #{config.full_pid_path}`.to_s if File.exist?(config.full_pid_path) - realpid = get_process pattern: get_config.daemon_process_name + listpid = get_processes({ :pattern => get_config.daemon_process_name}) pid.chomp! - realpid.chomp! + if listpid.empty? then + realpid = '' + else + realpid = listpid.first + end unless realpid.empty? then log.item "Splash Process is running with PID #{realpid} " else log.item 'Splash Process not found ' end