Class: Mrsk::Cli::Accessory
- Inherits:
-
Base
- Object
- Thor
- Base
- Mrsk::Cli::Accessory
show all
- Defined in:
- lib/mrsk/cli/accessory.rb
Instance Method Summary
collapse
Methods inherited from Base
exit_on_failure?, #initialize
Instance Method Details
#boot(name) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/mrsk/cli/accessory.rb', line 3
def boot(name)
if name == "all"
MRSK.accessory_names.each { |accessory_name| boot(accessory_name) }
else
with_accessory(name) do |accessory|
directories(name)
upload(name)
on(accessory.host) do
execute *MRSK.auditor.record("accessory #{name} boot"), verbosity: :debug
execute *accessory.run
end
end
end
end
|
#details(name) ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'lib/mrsk/cli/accessory.rb', line 87
def details(name)
if name == "all"
MRSK.accessory_names.each { |accessory_name| details(accessory_name) }
else
with_accessory(name) do |accessory|
on(accessory.host) { puts capture_with_info(*accessory.info) }
end
end
end
|
#directories(name) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/mrsk/cli/accessory.rb', line 37
def directories(name)
with_accessory(name) do |accessory|
on(accessory.host) do
execute *MRSK.auditor.record("accessory #{name} create directories"), verbosity: :debug
accessory.directories.keys.each do |host_path|
execute *accessory.make_directory(host_path)
end
end
end
end
|
#exec(name, cmd) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/mrsk/cli/accessory.rb', line 100
def exec(name, cmd)
with_accessory(name) do |accessory|
case
when options[:interactive] && options[:reuse]
say "Launching interactive command with via SSH from existing container...", :magenta
run_locally { exec accessory.execute_in_existing_container_over_ssh(cmd) }
when options[:interactive]
say "Launching interactive command via SSH from new container...", :magenta
run_locally { exec accessory.execute_in_new_container_over_ssh(cmd) }
when options[:reuse]
say "Launching command from existing container...", :magenta
on(accessory.host) do
execute *MRSK.auditor.record("accessory #{name} cmd '#{cmd}'"), verbosity: :debug
capture_with_info(*accessory.execute_in_existing_container(cmd))
end
else
say "Launching command from new container...", :magenta
on(accessory.host) do
execute *MRSK.auditor.record("accessory #{name} cmd '#{cmd}'"), verbosity: :debug
capture_with_info(*accessory.execute_in_new_container(cmd))
end
end
end
end
|
#logs(name) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/mrsk/cli/accessory.rb', line 133
def logs(name)
with_accessory(name) do |accessory|
grep = options[:grep]
if options[:follow]
run_locally do
info "Following logs on #{accessory.host}..."
info accessory.follow_logs(grep: grep)
exec accessory.follow_logs(grep: grep)
end
else
since = options[:since]
lines = options[:lines].presence || ((since || grep) ? nil : 100)
on(accessory.host) do
puts capture_with_info(*accessory.logs(since: since, lines: lines, grep: grep))
end
end
end
end
|
#reboot(name) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/mrsk/cli/accessory.rb', line 50
def reboot(name)
with_accessory(name) do |accessory|
stop(name)
remove_container(name)
boot(name)
end
end
|
#remove(name) ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/mrsk/cli/accessory.rb', line 155
def remove(name)
if name == "all"
MRSK.accessory_names.each { |accessory_name| remove(accessory_name) }
else
with_accessory(name) do
stop(name)
remove_container(name)
remove_image(name)
remove_service_directory(name)
end
end
end
|
#remove_container(name) ⇒ Object
169
170
171
172
173
174
175
176
|
# File 'lib/mrsk/cli/accessory.rb', line 169
def remove_container(name)
with_accessory(name) do |accessory|
on(accessory.host) do
execute *MRSK.auditor.record("accessory #{name} remove container"), verbosity: :debug
execute *accessory.remove_container
end
end
end
|
#remove_image(name) ⇒ Object
179
180
181
182
183
184
185
186
|
# File 'lib/mrsk/cli/accessory.rb', line 179
def remove_image(name)
with_accessory(name) do |accessory|
on(accessory.host) do
execute *MRSK.auditor.record("accessory #{name} remove image"), verbosity: :debug
execute *accessory.remove_image
end
end
end
|
#remove_service_directory(name) ⇒ Object
189
190
191
192
193
194
195
196
|
# File 'lib/mrsk/cli/accessory.rb', line 189
def remove_service_directory(name)
with_accessory(name) do |accessory|
on(accessory.host) do
execute *MRSK.auditor.record("accessory #{name} remove service directory"), verbosity: :debug
execute *accessory.remove_service_directory
end
end
end
|
#restart(name) ⇒ Object
79
80
81
82
83
84
|
# File 'lib/mrsk/cli/accessory.rb', line 79
def restart(name)
with_accessory(name) do
stop(name)
start(name)
end
end
|
#start(name) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/mrsk/cli/accessory.rb', line 59
def start(name)
with_accessory(name) do |accessory|
on(accessory.host) do
execute *MRSK.auditor.record("accessory #{name} start"), verbosity: :debug
execute *accessory.start
end
end
end
|
#stop(name) ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/mrsk/cli/accessory.rb', line 69
def stop(name)
with_accessory(name) do |accessory|
on(accessory.host) do
execute *MRSK.auditor.record("accessory #{name} stop"), verbosity: :debug
execute *accessory.stop, raise_on_non_zero_exit: false
end
end
end
|
#upload(name) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/mrsk/cli/accessory.rb', line 20
def upload(name)
with_accessory(name) do |accessory|
on(accessory.host) do
execute *MRSK.auditor.record("accessory #{name} upload files"), verbosity: :debug
accessory.files.each do |(local, remote)|
accessory.ensure_local_file_present(local)
execute *accessory.make_directory_for(remote)
upload! local, remote
execute :chmod, "755", remote
end
end
end
end
|