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
|
# File 'lib/osctld/commands/container/stop.rb', line 17
def execute(ct)
manipulate(ct) do
progress('Stopping container')
ct.pool.autostart_plan.stop_ct(ct)
mode =
case opts.fetch(:method, 'shutdown_or_kill')
when 'shutdown_or_kill'
:stop
when 'shutdown_or_fail'
:shutdown
when 'kill'
:kill
else
error!("unknown stop method '#{opts[:method]}'")
end
if %i[freezing frozen].include?(ct.state)
if mode == :stop
mode = :kill
elsif mode == :shutdown
error!('The container is frozen, unable to shutdown')
end
end
begin
Hook.run(ct, :pre_stop)
rescue HookFailed => e
error!(e.message)
end
ct.cgparams.temporarily_expand_memory if ct.running?
run_conf = ct.get_run_conf
if run_conf.init_pid
promise = run_conf.get_exit_promise
else
ct.log(:debug, 'init_pid is not set, skipping exit promise')
end
begin
DistConfig.run(
ct.get_run_conf,
:stop,
mode:,
message: opts[:message],
timeout: opts[:timeout] || Container::DEFAULT_STOP_TIMEOUT
)
rescue ContainerControl::UserRunnerError
ct.log(:warn, 'Unable to stop, killing by force')
progress('Unable to stop, killing by force')
unless force_kill(ct)
ct.log(:warn, 'Unable to kill or cleanup')
error!('Unable to kill or cleanup')
end
rescue ContainerControl::Error => e
error!(e.message)
end
if promise
if promise.wait
ct.log(:debug, 'Exit promise fulfilled')
else
ct.log(:warn, 'Timeout while waiting for exit promise')
end
end
remove_accounting_cgroups(ct)
if ct.ephemeral? && !indirect?
call_cmd!(
Commands::Container::Delete,
pool: ct.pool.name,
id: ct.id,
force: true
)
end
ok
end
end
|