Class: OsCtld::ContainerControl::Commands::Stop::Frontend

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

Constant Summary

Constants inherited from Frontend

Frontend::FAILED_RUNNER_GRACE

Instance Attribute Summary

Attributes inherited from Frontend

#command_class, #ct

Instance Method Summary collapse

Methods included from Utils::Wall::Frontend

#make_message

Methods inherited from Frontend

#cleanup_runner_cgroup, #exec_runner, #fork_runner, #initialize, #reap_failed_runner, #runner_result, #write_runner_failure

Constructor Details

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

Instance Method Details

#execute(mode, **opts) ⇒ true

Parameters:

  • mode (:stop, :shutdown, :kill)
  • opts (Hash) —

    options

Options Hash (**opts):

  • :timeout (Integer) —

    how log to wait for clean shutdown

  • :message (String, nil)

Returns:

  • (true)


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/osctld/container_control/commands/stop.rb', line 24

def execute(mode, **opts)
  unless %i[stop shutdown kill].include?(mode)
    raise ArgumentError, "invalid stop mode '#{mode}'"
  end

  if opts[:message] && ct.running?
    opts = opts.merge(message: make_message(opts[:message]))
  else
    opts.delete(:message)
  end

  ret =
    if mode == :kill
      with_forced_teardown { fork_runner(args: [mode, opts]) }
    elsif %i[stop shutdown].include?(mode) && ct.running?
      exec_runner(
        args: [mode, opts.merge(halt_from_inside: true)],
        switch_extra_namespaces: false
      )
    else
      fork_runner(args: [mode, opts])
    end

  if ret.ok?
    # LXC cannot remove a payload still containing the shutdown runner.
    # exec_runner has now reaped it and removed its osctl.attach leaf.
    # Remove the empty payload before the next start chooses a suffixed
    # cgroup and leaves helpers in the old, unsuffixed sibling.
    CGroup.rmpath_all(ct.payload_cgroup_path)
    true

  elsif mode == :stop
    ret = with_forced_teardown { fork_runner(args: [:kill, opts]) }
    CGroup.rmpath_all(ct.payload_cgroup_path) if ret.ok?
    ret.ok? || ret

  else
    ret
  end
end

#with_forced_teardown ⇒ Object (protected)



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/osctld/container_control/commands/stop.rb', line 67

def with_forced_teardown
  run_conf = ct.get_run_conf
  # Leave the LXC monitor runnable to receive the stop command.
  payload = File.join(ct.cgroup_path, "lxc.payload.#{ct.id}")
  run_conf.nfs_cancellation.capture(run_conf.init_pid)
  # A previously frozen parent also freezes the LXC monitor. Replace
  # that freeze with a payload-only one before establishing the barrier.
  CGroup.thaw_tree(ct.cgroup_path)
  CGroup.freeze_tree(payload)
  # Cancel first: a task blocked on NFS might not freeze until woken.
  run_conf.nfs_cancellation.abort
  CGroup.wait_frozen(payload)
  # Capture work admitted while the initial freeze was in progress.
  run_conf.nfs_cancellation.abort
  yield
ensure
  CGroup.thaw_tree(payload) if payload
end