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

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

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

#exec_runner, #fork_runner, #initialize

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

  CGroup.thaw_tree(ct.cgroup_path) if mode == :kill

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

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

  if ret.ok?
    true

  elsif mode == :stop
    CGroup.thaw_tree(ct.cgroup_path)
    ret = fork_runner(args: [:kill, opts])
    ret.ok? || ret

  else
    ret
  end
end