Class: OsCtld::Commands::Pool::Export
- Inherits:
-
Base
- Object
- Base
- OsCtld::Commands::Pool::Export
show all
- Includes:
- OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
- Defined in:
- lib/osctld/commands/pool/export.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!(pool) ⇒ Object
175
176
177
|
# File 'lib/osctld/commands/pool/export.rb', line 175
def check_abort!(pool)
error!('pool export aborted') if check_abort?(pool)
end
|
#check_abort?(pool) ⇒ Boolean
179
180
181
|
# File 'lib/osctld/commands/pool/export.rb', line 179
def check_abort?(pool)
pool.abort_export? || (indirect? && Daemon.get.abort_shutdown?)
end
|
#execute ⇒ Object
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
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
94
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
124
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
|
# File 'lib/osctld/commands/pool/export.rb', line 10
def execute
pool = DB::Pools.find(opts[:name])
unless pool
if opts[:if_imported]
progress('pool not imported')
return ok
else
error!('pool not imported')
end
end
if !opts[:force] && DB::Containers.get.detect { |ct| ct.pool == pool && ct.running? }
error!('the pool has running containers')
end
begin
Hook.run(pool, :pre_export)
rescue HookFailed => e
error!("pre-export hook failed: #{e.message}")
end
manipulate(pool) do
pool.begin_export
pool.begin_stop
check_abort!(pool)
pool.exclusively { pool.disable }
check_abort!(pool)
grab_cts(pool) unless opts[:grab_containers] === false
check_abort!(pool)
if opts[:stop_containers]
progress('Stopping all containers')
pool.autostop_and_wait(client_handler:, message: opts[:message])
check_abort!(pool)
loop do
all_stopped = true
DB::Containers.get.each do |ct|
next if ct.pool != pool
next if %i[staged stopped].include?(ct.state)
msg = "Container #{ct.ident} is still #{ct.state}, waiting until stopped"
progress(msg)
log(:warn, msg)
all_stopped = false
end
check_abort!(pool)
break if all_stopped
check_abort!(pool)
sleep(1)
end
end
pool.all_stop
progress('Unregistering users, groups and containers')
root_group = DB::Groups.root(pool)
[
DB::Containers,
DB::Users,
DB::Groups,
DB::Repositories,
DB::IdRanges
].each do |klass|
klass.get.each do |obj|
next if obj.pool != pool
if obj.is_a?(User)
obj.exclusively { UserControl::Supervisor.stop_server(obj) }
if opts[:unregister_users] && opts[:stop_containers]
call_cmd!(
Commands::User::Unregister,
pool: pool.name,
name: obj.name
)
syscmd("rm -rf \"#{obj.userdir}\"")
end
elsif obj.is_a?(Container)
obj.unregister
Monitor::Master.demonitor(obj)
Console.remove(obj)
end
klass.remove(obj)
obj.release_manipulation_lock if obj.is_a?(Container)
end
end
if opts[:stop_containers]
progress('Removing cgroups')
begin
CGroup.rmpath_all(root_group.cgroup_path)
rescue SystemCallError
end
BpfFs.remove_pool(pool.name)
end
call_cmd!(Commands::User::SubUGIds)
call_cmd!(Commands::User::LxcUsernet)
History.close(pool)
DB::Pools.remove(pool)
SendReceive.deploy
end
Hook.run(pool, :post_export)
ok
end
|
#grab_cts(pool) ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/osctld/commands/pool/export.rb', line 156
def grab_cts(pool)
progress('Grabbing all containers')
cts = DB::Containers.get.select { |ct| ct.pool == pool }
loop do
cts.delete_if do |ct|
ct.acquire_manipulation_lock(self)
true
rescue ResourceLocked => e
progress(e.message)
false
end
break if cts.empty?
sleep(1)
end
end
|