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
|
# File 'lib/osctld/commands/container/delete.rb', line 16
def execute(ct)
unless opts[:force]
ct.exclusively do
error!('the container is running') if ct.running?
end
end
manipulate(ct) do
progress('Stopping container')
call_cmd!(
Commands::Container::Stop,
pool: ct.pool.name,
id: ct.id,
manipulation_lock: opts[:manipulation_lock],
progress: opts[:progress],
message: opts[:message]
)
if ct.send_log
SendReceive.stopped_using_key(ct.pool, ct.send_log.opts.key_name)
end
progress('Disconnecting console')
Console.remove(ct)
progress('Removing shared mount directory')
ct.
ct.mounts.shared_dir.remove
progress('Moving dataset to trash')
trash_dataset(ct)
progress('Removing LXC configuration and script hooks')
Monitor::Master.demonitor(ct)
syscmd("rm -rf #{ct.lxc_dir} #{ct.user_hook_script_dir}")
if File.exist?(ct.log_path)
File.rename(ct.log_path, "#{ct.log_path}.destroyed")
end
File.unlink(ct.config_path)
progress('Unregistering container')
DB::Containers.remove(ct)
ct.pool.autostart_plan.clear_ct(ct)
progress('Removing cgroups')
begin
if ct.group.has_containers?(ct.user)
CGroup.rmpath_all(ct.base_cgroup_path)
else
CGroup.rmpath_all(ct.group.full_cgroup_path(ct.user))
end
rescue SystemCallError
end
if AppArmor.enabled?
progress('Removing AppArmor profile')
ct.apparmor.destroy_namespace
ct.apparmor.destroy_profile
end
bashrc = File.join(ct.lxc_dir, '.bashrc')
FileUtils.rm_f(bashrc)
unless ct.group.has_containers?(ct.user)
Dir.rmdir(ct.group.userdir(ct.user))
end
end
if !ct.user.standalone && !ct.user.has_containers?
call_cmd!(
Commands::User::Delete,
pool: ct.user.pool.name,
name: ct.user.name
)
end
progress('Reconfiguring LXC usernet')
call_cmd(Commands::User::LxcUsernet)
ct.pool.trash_bin.prune if opts[:prune]
ok
end
|