Module: Splash::WebAdmin::Controller

Includes:
Config, Constants, Exiter, Helpers, Loggers
Included in:
CLISplash::WebAdmin
Defined in:
lib/splash/webadmin.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

Exiter::EXIT_MAP

Instance Method Summary collapse

Methods included from Loggers

#change_logger, #get_logger, #get_session

Methods included from Config

#get_config, #rehash_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

#splash_exit, #splash_return

Instance Method Details

#startweb(options = {}) ⇒ Hash

Start the Splash Daemon

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :quiet (Symbol)

    activate quiet mode for log (limit to :fatal)

  • :foreground (Symbol)

    run webadmin in foreground

Returns:

  • (Hash)

    Exiter Case (:quiet_exit, :already_exist, :unknown_error or other)



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
# File 'lib/splash/webadmin.rb', line 25

def startweb(options = {})
  require 'splash/webadmin/main'
  config = get_config
  log = get_logger
  log.level = :fatal if options[:quiet]
  realpid = get_processes pattern: get_config.webadmin_process_name


  unless File::exist? config.webadmin_full_pid_path then
    unless realpid.empty? then
      return {:case => :already_exist, :more => "Splash WebAdmin Process already launched "}
    end

    daemon_config = {:description => config.webadmin_process_name,
        :pid_file => config.webadmin_full_pid_path,
        :stdout_trace => config.webadmin_full_stdout_trace_path,
        :stderr_trace => config.webadmin_full_stderr_trace_path,
        :foreground => options[:foreground]
      }

    ["int","term","hup"].each do |type| daemon_config["sig#{type}_handler".to_sym] = Proc::new {  WebAdminApp.quit! } end
    res = daemonize daemon_config do
      log = get_logger logger: :web, force: true
      log.info "Starting Splash WebAdmin"
      WebAdminApp.run!
    end
    sleep 1
    if res == 0 then
      pid = `cat #{config.webadmin_full_pid_path}`.to_i
      log.ok "Splash WebAdmin Started, with PID : #{pid}"
      return {:case => :quiet_exit, :more => "Splash WebAdmin successfully loaded."}
    else
      return {:case => :unknown_error, :more => "Splash WebAdmin loading error, see logs for more details."}
    end

  else
    return {:case => :already_exist, :more => "Pid File, please verify if Splash WebAdmin is running."}
  end
end

#statusweb(options = {}) ⇒ Hash

Status of the Splash WebAdmin, display status

Parameters:

  • options (Hash) (defaults to: {})

    ignored

Returns:

  • (Hash)

    Exiter Case (:status_ko, :status_ok)



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/splash/webadmin.rb', line 91

def statusweb(options = {})
  log = get_logger
  config = get_config
  pid = realpid = ''
  pid = `cat #{config.webadmin_full_pid_path}`.to_s if File.exist?(config.webadmin_full_pid_path)
  listpid = get_processes({ :pattern => get_config.webadmin_process_name})
  pid.chomp!
  if listpid.empty? then
    realpid = ''
  else
    realpid = listpid.first
  end
  unless realpid.empty? then
    log.item "Splash  WebAdmin Process is running with PID #{realpid} "
  else
    log.item 'Splash  WebAdminProcess 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 WebAdmin missing, run 'splash webadmin stop' before reload properly"}
  end
end

#stopweb(options = {}) ⇒ Hash

Stop the Splash WebAdmin

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :quiet (Symbol)

    activate quiet mode for log (limit to :fatal)

Returns:

  • (Hash)

    Exiter Case (:quiet_exit, :not_found, other)



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/splash/webadmin.rb', line 69

def stopweb(options = {})
    config = get_config
    log = get_logger
    log.level = :fatal if options[:quiet]
    if File.exist?(config.webadmin_full_pid_path) then
      begin
        pid = `cat #{config.webadmin_full_pid_path}`.to_i
        Process.kill("TERM", pid)
        acase = {:case => :quiet_exit, :more => 'Splash WebAdmin stopped succesfully'}
      rescue Errno::ESRCH
        acase =  {:case => :not_found, :more => "Process of PID : #{pid} not found"}
      end
      FileUtils::rm config.webadmin_full_pid_path if File::exist? config.webadmin_full_pid_path
    else
      acase =  {:case => :not_found, :more => "Splash WebAdmin is not running"}
    end
    return acase
end