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

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

Instance Attribute Summary

Attributes inherited from Runner

#ctid, #log_file, #lxc_home, #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, #initialize, #lxc_ct, #ok, #setup_exec_env, #setup_exec_run_env, #system_path

Constructor Details

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

Instance Method Details

#do_kill(_opts) ⇒ Object (protected)



90
91
92
93
94
95
# File 'lib/osctld/container_control/commands/stop.rb', line 90

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

#do_shutdown(opts) ⇒ Object (protected)



82
83
84
85
86
87
88
# File 'lib/osctld/container_control/commands/stop.rb', line 82

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 (protected)



74
75
76
77
78
79
80
# File 'lib/osctld/container_control/commands/stop.rb', line 74

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
      # ignore
    end
  end

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

#run_haltObject (protected)



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/osctld/container_control/commands/stop.rb', line 97

def run_halt
  pid = lxc_ct.attach do
    setup_exec_env

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

  Process.wait(pid) if pid && pid > 1
end