Class: OsCtld::ContainerControl::Commands::Stop::Runner

Inherits:
Runner
  • Object
show all
Includes:
Utils::Wall::Runner
Defined in:
lib/osctld/container_control/commands/stop.rb

Constant Summary

Constants inherited from Runner

Runner::LXC_ATTACH_FLAGS

Instance Attribute Summary

Attributes inherited from Runner

#ctid, #log_file, #lxc_home, #network_socket, #pool, #stderr, #stdin, #stdout, #user_home

Instance Method Summary collapse

Methods included from Utils::Wall::Runner

#ct_wall, #write_to_tty

Methods inherited from Runner

#error, #exitstatus, #initialize, #lxc_attach_command, #lxc_attach_wait, #lxc_attach_wait_for_exit, #lxc_ct, #ok, #reap_interrupted_lxc_attach, #setup_exec_env, #setup_exec_run_env, #system_path, #wait_for_lxc_attachable, #wait_for_lxc_stopped, #wait_for_path, #wait_for_process, #wait_status_exitstatus

Constructor Details

This class inherits a constructor from OsCtld::ContainerControl::Runner

Instance Method Details

#do_kill(_opts) ⇒ Object (protected)



127
128
129
130
131
132
# File 'lib/osctld/container_control/commands/stop.rb', line 127

def do_kill(_opts)
  lxc_ct.stop
  ok
rescue LXC::Error
  error('unable to kill container')
end

#do_shutdown(opts) ⇒ Object (protected)



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/osctld/container_control/commands/stop.rb', line 112

def do_shutdown(opts)
  timeout = opts[:timeout]

  if opts[:halt_from_inside]
    halt_seconds = run_halt(timeout)
    timeout -= halt_seconds
    timeout = 60 if timeout < 60
  end

  lxc_ct.shutdown(timeout)
  ok
rescue LXC::Error
  error('unable to shutdown container')
end

#do_stop(opts) ⇒ Object (protected)



104
105
106
107
108
109
110
# File 'lib/osctld/container_control/commands/stop.rb', line 104

def do_stop(opts)
  if do_shutdown(opts)[:status]
    ok
  else
    error('kill required')
  end
end

#execute(mode, opts) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/osctld/container_control/commands/stop.rb', line 90

def execute(mode, opts)
  if opts[:message]
    begin
      ct_wall(opts[:message])
    rescue LXC::Error
      # ignore
    end
  end

  send(:"do_#{mode}", opts)
end

#run_halt(timeout) ⇒ Integer (protected)

Returns halt duration in seconds.

Returns:

  • (Integer) —

    halt duration in seconds



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/osctld/container_control/commands/stop.rb', line 135

def run_halt(timeout)
  t1 = Time.now

  lxc_attach_wait(timeout:) do
    setup_exec_env

    %w[halt poweroff shutdown].each do |cmd|
      LXC.run_command(cmd)
    rescue LXC::Error
      next
    end
  end

  Time.now - t1
end