Class: OsCtld::Commands::Self::Shutdown
- Inherits:
-
Base
- Object
- Base
- OsCtld::Commands::Self::Shutdown
show all
- Defined in:
- lib/osctld/commands/self/shutdown.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #client_handler, #id, #opts
Instance Method Summary
collapse
Methods inherited from Base
#base_execute, #call_cmd, #call_cmd!, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!
Instance Method Details
#check_abort! ⇒ Object
165
166
167
|
# File 'lib/osctld/commands/self/shutdown.rb', line 165
def check_abort!
error!('shutdown aborted') if Daemon.get.abort_shutdown?
end
|
#check_abort? ⇒ Boolean
169
170
171
|
# File 'lib/osctld/commands/self/shutdown.rb', line 169
def check_abort?
Daemon.get.abort_shutdown?
end
|
#execute ⇒ Object
7
8
9
|
# File 'lib/osctld/commands/self/shutdown.rb', line 7
def execute
Daemon.get.run_shutdown { execute_shutdown }
end
|
#execute_shutdown ⇒ Object
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/osctld/commands/self/shutdown.rb', line 13
def execute_shutdown
grabbed_pools = []
grabbed_cts = []
wall_msg =
if opts[:wall]
opts[:message] || 'System is shutting down'
end
grab_pools(grabbed_pools)
check_abort!
DB::Pools.get.each do |pool|
progress("Disabling pool #{pool.name}")
pool.exclusively { pool.disable }
end
check_abort!
grab_all_cts(grabbed_cts)
check_abort!
stop_pools = DB::Pools.get
if stop_pools.length > 1
progress('Stopping all containers')
progress_tracker = ProgressTracker.new
stop_pools.each do |pool|
break if check_abort?
pool.begin_stop
pool.autostop_no_wait(message: wall_msg, client_handler:, progress_tracker:)
end
stop_pools.each do |pool|
break if check_abort?
pool.wait_for_autostop
end
check_abort!
end
DB::Pools.get.each do |pool|
check_abort!
progress("Exporting pool #{pool.name}")
call_cmd!(
Commands::Pool::Export,
name: pool.name,
force: true,
grab_containers: false,
stop_containers: true,
unregister_users: false,
message: wall_msg
)
end
ok
ensure
original_error = $!
cleanup_error = nil
Thread.handle_interrupt(Exception => :never) do
[grabbed_cts, grabbed_pools].each do |grabbed|
release_grabbed(grabbed)
rescue Exception => e cleanup_error ||= e
end
end
raise cleanup_error if cleanup_error && original_error.nil?
end
|
#grab_all_cts(grabbed) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/osctld/commands/self/shutdown.rb', line 125
def grab_all_cts(grabbed)
progress('Grabbing all containers')
cts = DB::Containers.get
loop do
break if check_abort?
cts.delete_if do |ct|
break if check_abort?
begin
Thread.handle_interrupt(Exception => :never) do
ct.acquire_manipulation_lock(self)
grabbed << ct
end
true
rescue ResourceLocked => e
progress(e.message)
false
end
end
break if cts.empty?
sleep(1)
end
grabbed
end
|
#grab_pools(grabbed) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/osctld/commands/self/shutdown.rb', line 95
def grab_pools(grabbed)
progress('Grabbing pools')
pools = DB::Pools.get
loop do
break if check_abort?
pools.delete_if do |pool|
break if check_abort?
begin
Thread.handle_interrupt(Exception => :never) do
pool.acquire_manipulation_lock(self)
grabbed << pool
end
true
rescue ResourceLocked => e
progress(e.message)
false
end
end
break if pools.empty?
sleep(1)
end
grabbed
end
|
#release_grabbed(grabbed) ⇒ Object
155
156
157
158
159
160
161
162
163
|
# File 'lib/osctld/commands/self/shutdown.rb', line 155
def release_grabbed(grabbed)
error = nil
grabbed.reverse_each do |v|
v.release_manipulation_lock if v.manipulated_by.equal?(self)
rescue Exception => e error ||= e
end
raise error if error
end
|