Class: OsCtld::ContainerControl::Commands::StopRunit::Runner

Inherits:
Runner
  • Object
show all
Defined in:
lib/osctld/container_control/commands/stop_runit.rb

Instance Attribute Summary

Attributes inherited from Runner

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

Instance Method Summary collapse

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

#executeInteger

Returns exit status.

Returns:

  • (Integer)

    exit status



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
# File 'lib/osctld/container_control/commands/stop_runit.rb', line 22

def execute
  pid = lxc_ct.attach do
    setup_exec_env
    ENV['HOME'] = '/root'
    ENV['USER'] = 'root'

    next unless Dir.exist?('/etc/runit')

    # Only the existence of the reboot file can trigger reboot
    if File.exist?('/etc/runit/reboot')
      File.open('/etc/runit/reboot', 'w', 0) {}
      File.chmod(0, '/etc/runit/reboot')
    end

    File.open('/etc/runit/stopit', 'w', 0100) {}
    File.chmod(0100, '/etc/runit/stopit')
  end

  Process.wait(pid)

  if $?.exitstatus == 0
    ok
  else
    log(:warn, ct, "runit-stop exited with #{$?.exitstatus}")
    error('runit-stop failed')
  end
end