lib/splash/controller.rb in prometheus-splash-0.3.0 vs lib/splash/controller.rb in prometheus-splash-0.4.0
- old
+ new
@@ -4,29 +4,38 @@
module DaemonController
include Splash::Constants
include Splash::Helpers
include Splash::Config
include Splash::Orchestrator
+ include Splash::Exiter
+ include Splash::Loggers
def startdaemon(options = {})
config = get_config
+ log = get_logger
unless verify_service host: config.prometheus_pushgateway_host ,port: config.prometheus_pushgateway_port then
return {:case => :service_dependence_missing, :more => 'Prometheus Gateway'}
end
unless File::exist? config.full_pid_path then
- res = daemonize :description => config.daemon_process_name,
+ 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] do
+ :stderr_trace => config.full_stderr_trace_path,
+ :foreground => options[:foreground]
+ }
+
+ ["int","term","hup"].each do |type| daemon_config["sig#{type}_handler".to_sym] = Proc::new { ObjectSpace.each_object(Splash::Orchestrator::Scheduler).first.shutdown } end
+ res = daemonize daemon_config do
Scheduler::new options
end
+ sleep 1
if res == 0 then
pid = `cat #{config.full_pid_path}`.to_i
- puts "Splash Daemon Started, with PID : #{pid}"
- return {:case => :quiet_exit}
+ log.ok "Splash Daemon Started, with PID : #{pid}"
+ return {:case => :quiet_exit, :more => "Splash Daemon successfully loaded."}
else
- return {:case => :unknown_error, :more => "Splash Daemon loading error, see logs for more details"}
+ return {:case => :unknown_error, :more => "Splash Daemon loading error, see logs for more details."}
end
else
return {:case => :already_exist, :more => "Pid File, please verify if Splash daemon is running."}
end
@@ -47,25 +56,26 @@
acase = {:case => :not_found, :more => "Splash is not running"}
end
return acase
end
- def statusdaemon
+ 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
pid.chomp!
realpid.chomp!
unless realpid.empty? then
- print "Splash Process is running with PID #{realpid} "
+ log.item "Splash Process is running with PID #{realpid} "
else
- print 'Splash Process not found '
+ log.item 'Splash Process not found '
end
unless pid.empty? then
- puts "and PID file exist with PID #{pid}"
+ log.item "and PID file exist with PID #{pid}"
else
- puts "and PID file don't exist"
+ log.item "and PID file don't exist"
end
if pid == realpid then
return {:case => :status_ok }
elsif pid.empty? then
return {:case => :status_ko, :more => "PID File error, you have to kill process manualy, with : '(sudo )kill -TERM #{realpid}'"}