lib/splash/controller.rb in prometheus-splash-0.1.0 vs lib/splash/controller.rb in prometheus-splash-0.1.1
- old
+ new
@@ -1,6 +1,6 @@
-
+# coding: utf-8
module Splash
module LogsMonitor
module DaemonController
include Splash::Constants
include Splash::Helpers
@@ -8,13 +8,11 @@
include Splash::Orchestrator
def startdaemon(options = {})
config = get_config
unless verify_service host: config.prometheus_pushgateway_host ,port: config.prometheus_pushgateway_port then
- $stderr.puts "Prometheus PushGateway Service is not running,"
- $stderr.puts " please start before running Splash daemon."
- exit 11
+ return {:case => :service_dependence_missing, :more => 'Prometheus Gateway'}
end
unless File::exist? config.full_pid_path then
res = daemonize :description => config.daemon_process_name,
:pid_file => config.full_pid_path,
@@ -23,40 +21,35 @@
Scheduler::new
end
if res == 0 then
pid = `cat #{config.full_pid_path}`.to_i
puts "Splash Daemon Started, with PID : #{pid}"
+ return {:case => :quiet_exit}
else
- $stderr.puts "Splash Daemon loading error"
+ return {:case => :unknown_error, :more => "Splash Daemon loading error"}
end
- return res
else
- $stderr.puts "Pid File already exist, please verify if Splash daemon is running."
- return 14
+ return {:case => :already_exist, :more => "Pid File, please verify if Splash daemon is running."}
end
end
def stopdaemon(options = {})
config = get_config
- errorcode = 0
if File.exist?(config.full_pid_path) then
-
begin
pid = `cat #{config.full_pid_path}`.to_i
Process.kill("TERM", pid)
- puts 'Splash stopped succesfully'
+ acase = {:case => :quiet_exit, :more => 'Splash stopped succesfully'}
rescue Errno::ESRCH
- $stderr.puts "Process of PID : #{pid} not found"
- errorcode = 12
+ acase = {:case => :not_found, :more => "Process of PID : #{pid} not found"}
end
FileUtils::rm config.full_pid_path if File::exist? config.full_pid_path
else
- $stderr.puts "Splash is not running"
- errorcode = 13
+ acase = {:case => :not_found, :more => "Splash is not running"}
end
- return errorcode
+ return acase
end
def statusdaemon
config = get_config
pid = realpid = ''
@@ -73,19 +66,14 @@
puts "and PID file exist with PID #{pid}"
else
puts "and PID file don't exist"
end
if pid == realpid then
- puts 'Status OK'
- return 0
+ return {:case => :status_ok }
elsif pid.empty? then
- $stderr.puts "PID File error, you have to kill process manualy, with : '(sudo )kill -TERM #{realpid}'"
- $stderr.puts "Status KO"
- return 16
+ return {:case => :status_ko, :more => "PID File error, you have to kill process manualy, with : '(sudo )kill -TERM #{realpid}'"}
elsif realpid.empty? then
- $stderr.puts "Process Splash Dameon missing, run 'splash daemon stop' to reload properly"
- $stderr.puts "Status KO"
- return 17
+ return {:case => :status_ko, :more => "Process Splash Dameon missing, run 'splash daemon stop' to reload properly"}
end
end
end
end