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

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

Instance Attribute Summary

Attributes inherited from Runner

#ctid, #log_file, #lxc_home, #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, #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

#execute(opts) ⇒ Integer

Returns exit status.

Parameters:

  • opts (Hash)

    options

Options Hash (opts):

  • :message (String, nil)

Returns:

  • (Integer)

    exit status



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

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

  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.new('/etc/runit/reboot', 'w', 0).close
      File.chmod(0, '/etc/runit/reboot')
    end

    File.new('/etc/runit/stopit', 'w', 0o100).close
    File.chmod(0o100, '/etc/runit/stopit')
  end

  Process.wait(pid)

  if $?.exitstatus == 0
    ok
  else
    error("runit-stop failed with exit status #{$?.exitstatus}")
  end
end