Class: OsCtld::ContainerControl::Commands::Stop::Runner
Instance Attribute Summary
Attributes inherited from Runner
#ctid, #log_file, #lxc_home, #stderr, #stdin, #stdout, #user_home
Instance Method Summary
collapse
#ct_wall, #write_to_tty
Methods inherited from Runner
#error, #initialize, #lxc_ct, #ok, #setup_exec_env, #setup_exec_run_env, #system_path
Instance Method Details
#do_kill(opts) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/osctld/container_control/commands/stop.rb', line 89
def do_kill(opts)
lxc_ct.stop
ok
rescue LXC::Error
error('unable to kill container')
end
|
#do_shutdown(opts) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/osctld/container_control/commands/stop.rb', line 81
def do_shutdown(opts)
run_halt if opts[:halt_from_inside]
lxc_ct.shutdown(opts[:timeout])
ok
rescue LXC::Error
error('unable to shutdown container')
end
|
#do_stop(opts) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/osctld/container_control/commands/stop.rb', line 73
def do_stop(opts)
if do_shutdown(opts)[:status]
ok
else
error('kill required')
end
end
|
#execute(mode, opts) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/osctld/container_control/commands/stop.rb', line 60
def execute(mode, opts)
if opts[:message]
begin
ct_wall(opts[:message])
rescue LXC::Error
end
end
send(:"do_#{mode}", opts)
end
|
#run_halt ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/osctld/container_control/commands/stop.rb', line 96
def run_halt
pid = lxc_ct.attach do
setup_exec_env
%w(halt poweroff shutdown).each do |cmd|
begin
LXC.run_command(cmd)
rescue LXC::Error
next
end
end
end
Process.wait(pid) if pid && pid > 1
end
|