Module: Splash::Daemon::Controller
- Included in:
- CLISplash::CLIController, WebAdminApp
- Defined in:
- lib/splash/daemon/controller.rb
Overview
Daemon Controller Module
Constant Summary
Constants included from Loggers
Loggers::ALIAS, Loggers::LEVELS
Constants included from Constants
Constants::AUTHOR, Constants::BACKENDS_STRUCT, Constants::CONFIG_FILE, Constants::COPYRIGHT, Constants::DAEMON_LOGMON_SCHEDULING, Constants::DAEMON_METRICS_SCHEDULING, Constants::DAEMON_PID_FILE, Constants::DAEMON_PROCESS_NAME, Constants::DAEMON_PROCMON_SCHEDULING, Constants::DAEMON_STDERR_TRACE, Constants::DAEMON_STDOUT_TRACE, Constants::DEFAULT_RETENTION, Constants::EMAIL, Constants::EXECUTION_TEMPLATE, Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Constants::LICENSE, Constants::LOGGERS_STRUCT, Constants::PID_PATH, Constants::PROMETHEUS_ALERTMANAGER_URL, Constants::PROMETHEUS_PUSHGATEWAY_URL, Constants::PROMETHEUS_URL, Constants::TRACE_PATH, Constants::TRANSPORTS_STRUCT, Constants::VERSION, Constants::WEBADMIN_IP, Constants::WEBADMIN_PID_FILE, Constants::WEBADMIN_PID_PATH, Constants::WEBADMIN_PORT, Constants::WEBADMIN_PROCESS_NAME, Constants::WEBADMIN_PROXY, Constants::WEBADMIN_STDERR_TRACE, Constants::WEBADMIN_STDOUT_TRACE
Constants included from Exiter
Instance Method Summary collapse
-
#startdaemon(options = {}) ⇒ Hash
Start the Splash Daemon.
-
#statusdaemon(options = {}) ⇒ Hash
Status of the Splash Daemon, display status.
-
#stopdaemon(options = {}) ⇒ Hash
Stop the Splash Daemon.
Methods included from Loggers
#change_logger, #get_logger, #get_session
Methods included from Config
Methods included from ConfigUtilities
#addservice, #checkconfig, #flush_backend, #setupsplash
Methods included from Helpers
#check_unicode_term, #daemonize, #format_by_extensions, #format_response, #get_processes, #group_root, #install_file, #is_root?, #make_folder, #make_link, #run_as_root, #search_file_in_gem, #user_root, #verify_file, #verify_folder, #verify_link, #verify_service
Methods included from Exiter
Instance Method Details
#startdaemon(options = {}) ⇒ Hash
Start the Splash Daemon
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/splash/daemon/controller.rb', line 25 def startdaemon( = {}) config = get_config log = get_logger log.level = :fatal if [:quiet] unless verify_service url: config.prometheus_pushgateway_url 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 [:foreground] then return {:case => :already_exist, :more => "Splash Process already launched on foreground "} end unless File::exist? config.daemon_full_pid_path then unless realpid.empty? then return {:case => :already_exist, :more => "Splash Process already launched "} end if [: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.daemon_full_pid_path, :stdout_trace => config.daemon_full_stdout_trace_path, :stderr_trace => config.daemon_full_stderr_trace_path, :foreground => [:foreground] } ["int","term","hup"].each do |type| daemon_config["sig#{type}_handler".to_sym] = Proc::new { ObjectSpace.each_object(Splash::Daemon::Orchestrator::Scheduler).first.terminate } end res = daemonize daemon_config do Scheduler::new end sleep 1 if res == 0 then pid = `cat #{config.daemon_full_pid_path}`.to_i 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."} end else return {:case => :already_exist, :more => "Pid File, please verify if Splash daemon is running."} end end |
#statusdaemon(options = {}) ⇒ Hash
Status of the Splash Daemon, display status
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/splash/daemon/controller.rb', line 103 def statusdaemon( = {}) log = get_logger config = get_config pid = realpid = '' pid = `cat #{config.daemon_full_pid_path}`.to_s if File.exist?(config.daemon_full_pid_path) listpid = get_processes({ :pattern => get_config.daemon_process_name}) pid.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 unless pid.empty? then log.item "and PID file exist with PID #{pid}" else 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}'"} elsif realpid.empty? then return {:case => :status_ko, :more => "Process Splash Dameon missing, run 'splash daemon stop' to reload properly"} end end |
#stopdaemon(options = {}) ⇒ Hash
Stop the Splash Daemon
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/splash/daemon/controller.rb', line 81 def stopdaemon( = {}) config = get_config log = get_logger log.level = :fatal if [:quiet] if File.exist?(config.daemon_full_pid_path) then begin pid = `cat #{config.daemon_full_pid_path}`.to_i Process.kill("TERM", pid) acase = {:case => :quiet_exit, :more => 'Splash stopped succesfully'} rescue Errno::ESRCH acase = {:case => :not_found, :more => "Process of PID : #{pid} not found"} end FileUtils::rm config.daemon_full_pid_path if File::exist? config.daemon_full_pid_path else acase = {:case => :not_found, :more => "Splash is not running"} end return acase end |