Module: Aptible::CLI::Subcommands::Restart

Included in:
Agent
Defined in:
lib/aptible/cli/subcommands/restart.rb

Class Method Summary collapse

Class Method Details

.included(thor) ⇒ Object



5
6
7
8
9
10
11
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
43
# File 'lib/aptible/cli/subcommands/restart.rb', line 5

def self.included(thor)
  thor.class_eval do
    include Helpers::Operation
    include Helpers::App

    desc 'restart', 'Restart all services associated with an app'
    option :simulate_oom,
           type: :boolean,
           desc: 'Add this flag to simulate an OOM restart and test ' \
                 "your app's response (not recommended on production " \
                 'apps).'
    option :force,
           type: :boolean,
           desc: 'Add this flag to use --simulate-oom in a ' \
                 'production environment, which is not allowed by ' \
                 'default.'
    app_options
    def restart
      app = ensure_app(options)
      type = 'restart'

      if options[:simulate_oom]
        type = 'captain_comeback_restart'

        if app..type == 'production' && !options[:force]
          e = 'This operation is designed for test purposes only, ' \
              "but #{app.handle} is deployed in a production " \
              'environment. Are you sure you want to do this? If ' \
              'so, use the --force flag.'
          raise Thor::Error, e
        end
      end

      operation = app.create_operation!(type: type)
      CLI.logger.info 'Restarting app...'
      attach_to_operation_logs(operation)
    end
  end
end