Class: Daemon::Command::StopCommand

Inherits:
BaseCommand show all
Defined in:
lib/onapp/engine/command/stop_command.rb

Overview

Used to stop onapp-engine system service

Constant Summary

TIMEOUT =
15
TIMEOUT_ERROR =
10
ERROR =
1
OK =
0

Instance Attribute Summary

Attributes inherited from BaseCommand

#options

Attributes included from UserInterface

#err, #out

Instance Method Summary (collapse)

Methods inherited from BaseCommand

#initialize

Methods included from UserInterface

#error, #say

Constructor Details

This class inherits a constructor from Daemon::Command::BaseCommand

Instance Method Details

- (Object) execute

Entry point



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
# File 'lib/onapp/engine/command/stop_command.rb', line 18

def execute
  say 'Stopping OnApp Engine...'

  if options.only_instances
    say 'Stopping OnApp Engine Workers...'
    master_pid = Daemon::MasterProcess.another_instance_pid
    if master_pid
      Process.kill(Daemon::MasterProcess::STOP_SIGNAL, master_pid)
    end
    return OK
  end

  if pids.count > 0
    Daemon.force_stop.set if options.forced
    say "#{pids.count} pids found: #{pids.join(', ')}"
    pids.each { |pid| terminate(pid) }
    if can_stop_immediately?
      return OK
    else
      say "#{Daemon::MasterProcess::PROCESS_NAME} (#{pids.join(', ')}) can't be stopped immediately"
      return TIMEOUT_ERROR
    end
  else
    say 'No running instances detected'
    return ERROR
  end
end