Module: Splash::LogsMonitor::DaemonController

Includes:
Config, Constants, Exiter, Helpers, Splash::Loggers, Orchestrator
Included in:
CLISplash::CLIController
Defined in:
lib/splash/controller.rb

Constant Summary

Constants included from Constants

Constants::AUTHOR, Constants::BACKENDS_STRUCT, Constants::CONFIG_FILE, Constants::COPYRIGHT, Constants::DAEMON_LOGMON_SCHEDULING, Constants::DAEMON_PID_FILE, Constants::DAEMON_PID_PATH, Constants::DAEMON_PROCESS_NAME, Constants::DAEMON_STDERR_TRACE, Constants::DAEMON_STDOUT_TRACE, Constants::EMAIL, Constants::EXECUTION_TEMPLATE, Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Constants::LICENSE, Constants::LOGGERS_STRUCT, Constants::PROMETHEUS_PUSHGATEWAY_HOST, Constants::PROMETHEUS_PUSHGATEWAY_PORT, Constants::TRACE_PATH, Constants::TRANSPORTS_STRUCT, Constants::VERSION

Constants included from Exiter

Exiter::EXIT_MAP

Instance Method Summary collapse

Methods included from Splash::Loggers

#change_logger, #get_logger

Methods included from Config

#get_config

Methods included from ConfigUtilities

#checkconfig, #setupsplash

Methods included from Helpers

#daemonize, #get_process, #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

#splash_exit

Instance Method Details

#startdaemon(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/splash/controller.rb', line 12

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
    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]
      }

    ["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
      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 = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/splash/controller.rb', line 61

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
    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 = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/splash/controller.rb', line 44

def stopdaemon(options = {})
    config = get_config
    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'}
      rescue Errno::ESRCH
        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
      acase =  {:case => :not_found, :more => "Splash is not running"}
    end
    return acase
end