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!, cmd, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!
Instance Method Details
#check_abort! ⇒ Object
135
136
137
|
# File 'lib/osctld/commands/self/shutdown.rb', line 135
def check_abort!
error!('shutdown aborted') if Daemon.get.abort_shutdown?
end
|
#check_abort? ⇒ Boolean
139
140
141
|
# File 'lib/osctld/commands/self/shutdown.rb', line 139
def check_abort?
Daemon.get.abort_shutdown?
end
|
#execute ⇒ Object
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/osctld/commands/self/shutdown.rb', line 7
def execute
Daemon.get.begin_shutdown
grabbed_pools = grab_pools
if check_abort?
release_grabbed(grabbed_pools)
error!('shutdown aborted')
end
DB::Pools.get.each do |pool|
progress("Disabling pool #{pool.name}")
pool.exclusively { pool.disable }
end
check_abort!
grabbed_cts = grab_all_cts
if check_abort?
release_grabbed(grabbed_cts)
release_grabbed(grabbed_pools)
error!('shutdown aborted')
end
DB::Pools.get.each do |pool|
if check_abort?
release_grabbed(grabbed_cts)
release_grabbed(grabbed_pools)
error!('shutdown aborted')
end
progress("Exporting pool #{pool.name}")
wall_msg =
if opts[:wall]
opts[:message] || 'System is shutting down'
else
nil
end
call_cmd!(
Commands::Pool::Export,
name: pool.name,
force: true,
grab_containers: false,
stop_containers: true,
unregister_users: false,
message: wall_msg,
)
end
Daemon.get.confirm_shutdown
ok
end
|
#grab_all_cts ⇒ Object
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
124
125
126
|
# File 'lib/osctld/commands/self/shutdown.rb', line 99
def grab_all_cts
progress('Grabbing all containers')
cts = DB::Containers.get
grabbed = []
loop do
break if check_abort?
cts.delete_if do |ct|
break if check_abort?
begin
ct.acquire_manipulation_lock(self)
grabbed << ct
true
rescue ResourceLocked => e
progress(e.message)
false
end
end
break if cts.empty?
sleep(1)
end
grabbed
end
|
#grab_pools ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/osctld/commands/self/shutdown.rb', line 70
def grab_pools
progress('Grabbing pools')
pools = DB::Pools.get
grabbed = []
loop do
break if check_abort?
pools.delete_if do |pool|
break if check_abort?
begin
pool.acquire_manipulation_lock(self)
grabbed << pool
true
rescue ResourceLocked => e
progress(e.message)
false
end
end
break if pools.empty?
sleep(1)
end
grabbed
end
|
#release_grabbed(grabbed) ⇒ Object
128
129
130
131
132
133
|
# File 'lib/osctld/commands/self/shutdown.rb', line 128
def release_grabbed(grabbed)
grabbed.each do |v|
v.release_manipulation_lock if v.manipulated_by == self
end
end
|