Class: Ruby::Nginx::Commands::StopNginx

Inherits:
TerminalCommand show all
Defined in:
lib/ruby/nginx/commands/stop_nginx.rb

Instance Attribute Summary

Attributes inherited from TerminalCommand

#cmd, #error_type, #printer, #result, #user

Instance Method Summary collapse

Methods included from Helpers::SudoHelper

#sudoify

Methods included from Helpers::PromptHelper

#yes?

Constructor Details

#initialize(sudo: false) ⇒ StopNginx

Returns a new instance of StopNginx.



9
10
11
12
13
14
# File 'lib/ruby/nginx/commands/stop_nginx.rb', line 9

def initialize(sudo: false)
  @sudo = sudo
  sudo_reason = "Allow sudo elevation to stop NGINX?"

  super(cmd: sudoify("nginx -s stop", sudo, sudo_reason), raise: Ruby::Nginx::StopError)
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby/nginx/commands/stop_nginx.rb', line 16

def run
  super
rescue Ruby::Nginx::StopError => e
  return if nginx_not_running_error?(e)

  if @sudo
    raise
  else
    # Elevate to sudo and try again.
    self.class.new(sudo: true).run
  end
end