Class: MockWS::Daemon::Controller
- Inherits:
-
Object
- Object
- MockWS::Daemon::Controller
- Extended by:
- Carioca::Injector
- Defined in:
- lib/mockws/daemon_controller.rb
Constant Summary collapse
- DAEMON_NAME =
"MockWS : Daemon"
- MOCKWS_PATH =
File::("~/.mockws")
- PID_FILE =
MOCKWS_PATH + "/mockws.pid"
- STDOUT_TRACE =
MOCKWS_PATH + "/stdout.trace"
- STDERR_TRACE =
MOCKWS_PATH + "/stderr.trace"
Class Method Summary collapse
- .start(options) ⇒ Object
-
.status(options = {}) ⇒ Hash
Status of the Splash WebAdmin, display status.
-
.stop(options = {}) ⇒ Object
Stop MockWS daemon.
Class Method Details
.start(options) ⇒ Object
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 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mockws/daemon_controller.rb', line 18 def self.start output.level = :fatal if [:quiet] realpid = toolbox.get_processes pattern: DAEMON_NAME unless File::exist? PID_FILE then unless realpid.empty? then finisher.secure_raise error_case: :already_exist, message: "MockWS Process already launched " end daemon_config = {:description => DAEMON_NAME, :pid_file => PID_FILE, :stdout_trace => STDOUT_TRACE, :stderr_trace => STDERR_TRACE, :foreground => [:foreground] } ["int","term","hup"].each do |type| daemon_config["sig#{type}_handler".to_sym] = Proc::new { MockWS::Service.quit! } end res = daemonize daemon_config do output.info "Starting MockWS Daemon" MockWS::Service::init MockWS::Service.run! end sleep 1 if res == 0 then pid = `cat #{PID_FILE}`.to_i output.ok "MockWS Started, with PID : #{pid}" output.ok "MockWS successfully loaded." else finisher.secure_raise error_case: :unknown_error, message: "MockWS loading error, see logs for more details." end else finisher.secure_raise error_case: :already_exist, message: "Pid File, please verify if MockWS is running." end end |
.status(options = {}) ⇒ Hash
Status of the Splash WebAdmin, display status
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/mockws/daemon_controller.rb', line 79 def self.status( = {}) pid = realpid = '' pid = `cat #{PID_FILE}`.to_s if File.exist?(PID_FILE) listpid = toolbox.get_processes pattern: DAEMON_NAME pid.chomp! if listpid.empty? then realpid = '' else realpid = listpid.first end unless realpid.empty? then output.item "MockWS daemon process is running with PID #{realpid} " else output.item 'MockWS daemon not found ' end unless pid.empty? then output.item "and PID file exist with PID #{pid}" else output.item "and PID file don't exist" end if pid == realpid then return "MockWS status clean" elsif pid.empty? then finisher.secure_raise error_case: :status_ko, message: "PID File error, you have to kill process manualy, with : '(sudo )kill -TERM #{realpid}'" elsif realpid.empty? then finisher.secure_raise error_case: :status_ko, message: "Process MockWS daemon missing, run 'mockws stop' before reload properly" end end |
.stop(options = {}) ⇒ Object
Stop MockWS daemon
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mockws/daemon_controller.rb', line 57 def self.stop( = {}) output.level = :fatal if [:quiet] if File.exist?(PID_FILE) then begin pid = `cat #{PID_FILE}`.to_i Process.kill("TERM", pid) output.ok 'Splash WebAdmin stopped succesfully' rescue Errno::ESRCH finisher.secure_raise error_case: :not_found, message: "Process of PID : #{pid} not found, erasing Pidfile " ensure FileUtils::rm PID_FILE if File::exist? PID_FILE end return "MockWS stopped" else finisher.secure_raise error_case: :not_found, message: "Splash WebAdmin is not running" end end |