Class: Mrsk::Cli::App

Inherits:
Base
  • Object
show all
Defined in:
lib/mrsk/cli/app.rb

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?, #initialize

Constructor Details

This class inherits a constructor from Mrsk::Cli::Base

Instance Method Details

#bashObject



58
59
60
61
62
63
# File 'lib/mrsk/cli/app.rb', line 58

def bash
  run_locally do
    info "Launching bash session on #{MRSK.primary_host}"
    exec MRSK.app.bash(host: MRSK.primary_host)
  end
end

#bootObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mrsk/cli/app.rb', line 5

def boot
  MRSK.config.roles.each do |role|
    on(role.hosts) do |host|
      begin
        execute *MRSK.app.run(role: role.name)
      rescue SSHKit::Command::Failed => e
        if e.message =~ /already in use/
          error "Container with same version already deployed on #{host}, starting that instead"
          execute *MRSK.app.start, host: host
        else
          raise
        end
      end
    end
  end
end

#consoleObject



50
51
52
53
54
55
# File 'lib/mrsk/cli/app.rb', line 50

def console
  run_locally do
    info "Launching Rails console on #{MRSK.primary_host}"
    exec MRSK.app.console(host: MRSK.primary_host)
  end
end

#containersObject



71
72
73
# File 'lib/mrsk/cli/app.rb', line 71

def containers
  on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.list_containers) }
end

#currentObject



76
77
78
# File 'lib/mrsk/cli/app.rb', line 76

def current
  on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.current_container_id) }
end

#detailsObject



38
39
40
# File 'lib/mrsk/cli/app.rb', line 38

def details
  on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.info) }
end

#exec(cmd) ⇒ Object



44
45
46
47
# File 'lib/mrsk/cli/app.rb', line 44

def exec(cmd)
  runner = options[:run] ? :run_exec : :exec
  on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.send(runner, cmd)) }
end

#logsObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/mrsk/cli/app.rb', line 85

def logs
  # FIXME: Catch when app containers aren't running

  grep = options[:grep]

  if options[:follow]
    run_locally do
      info "Following logs on #{MRSK.primary_host}..."
      info MRSK.app.follow_logs(host: MRSK.primary_host, grep: grep)
      exec MRSK.app.follow_logs(host: MRSK.primary_host, grep: grep)
    end
  else
    since = options[:since]
    lines = options[:lines]

    on(MRSK.hosts) do |host|
      begin
        puts_by_host host, capture_with_info(*MRSK.app.logs(since: since, lines: lines, grep: grep))
      rescue SSHKit::Command::Failed
        puts_by_host host, "Nothing found"
      end
    end
  end
end

#removeObject



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/mrsk/cli/app.rb', line 112

def remove
  case options[:only]
  when "containers"
    on(MRSK.hosts) { execute *MRSK.app.remove_containers }
  when "images"
    on(MRSK.hosts) { execute *MRSK.app.remove_images }
  else
    on(MRSK.hosts) { execute *MRSK.app.remove_containers }
    on(MRSK.hosts) { execute *MRSK.app.remove_images }
  end
end

#runner(expression) ⇒ Object



66
67
68
# File 'lib/mrsk/cli/app.rb', line 66

def runner(expression)
  on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.exec("bin/rails", "runner", "'#{expression}'")) }
end

#startObject



24
25
26
27
28
29
30
# File 'lib/mrsk/cli/app.rb', line 24

def start
  if (version = options[:version]).present?
    on(MRSK.hosts) { execute *MRSK.app.start(version: version) }
  else
    on(MRSK.hosts) { execute *MRSK.app.start, raise_on_non_zero_exit: false }
  end
end

#stopObject



33
34
35
# File 'lib/mrsk/cli/app.rb', line 33

def stop
  on(MRSK.hosts) { execute *MRSK.app.stop, raise_on_non_zero_exit: false }
end