Method: ContainerManagerAdapter::Vserver#stop

Defined in:
lib/wf_node_api/container_manager_adapter/vserver.rb

#stop(name) ⇒ String

Stops a container with the given name

Parameters:

  • name (String)

    The container name

Returns:

  • (String)

    CLI output

Raises:

  • (RuntimeError)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/wf_node_api/container_manager_adapter/vserver.rb', line 73

def stop(name)
  if state(name) == 'STOPPED'
    $logger.warn("container " + name + " could not be stopped, because it is not running")
    raise RuntimeError, 'container is not running'
  end

  res = Open3.capture3($vserver_cmd_stop.gsub('[name]', name))

  if res[2].exitstatus == 0 && state(name) == 'STOPPED'
    $logger.info("container " + name + " successfully stopped")
    return res[0].strip
  end

  $logger.warn("container " + name + " could not be stopped")
  raise RuntimeError, res[1].strip
end