Class: OsCtld::ContainerControl::Commands::Runscript::Runner

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

Instance Attribute Summary

Attributes inherited from Runner

#ctid, #log_file, #lxc_home, #user_home

Instance Method Summary collapse

Methods included from Utils::Runscript::Runner

#runscript_run, #with_configured_network

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(mode, opts) ⇒ Integer

Returns exit status.

Parameters:

  • mode (:running, :run_network, :run)
  • opts (Hash)

Options Hash (opts):

  • :script (String)

    path to the script relative to the rootfs

  • :args (Array<String>)

    script arguments

  • :stdin (IO)
  • :stdout (IO)
  • :stderr (IO)
  • :run (Boolean)

    run the container if it is stopped?

  • :network (Boolean)

    setup network if the container is run?

  • :init_script (String)

    path to the script used to control the container

  • :net_config (NetConfig)
  • :close_fds (Array<IO>)
  • :wait (Boolean)

Returns:

  • (Integer)

    exit status



84
85
86
# File 'lib/osctld/container_control/commands/runscript.rb', line 84

def execute(mode, opts)
  send(:"runscript_#{mode}", opts)
end

#runscript_run_network(opts) ⇒ Object (protected)



117
118
119
120
121
122
# File 'lib/osctld/container_control/commands/runscript.rb', line 117

def runscript_run_network(opts)
  with_configured_network(
    init_script: opts[:init_script],
    net_config: opts[:net_config],
  ) { runscript_running(opts) }
end

#runscript_running(opts) ⇒ Object (protected)



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/osctld/container_control/commands/runscript.rb', line 89

def runscript_running(opts)
  pid = lxc_ct.attach(
    stdin: opts[:stdin],
    stdout: opts[:stdout],
    stderr: opts[:stderr]
  ) do
    setup_exec_env
    ENV['HOME'] = '/root'
    ENV['USER'] = 'root'

    # FIXME: *something* must be keeping opts[:script] open, because when
    # runscript is run in parallel, 1-2 out of 10 calls fail with ETXTBSY,
    # which LXC translates to LXC::Error. So we try to call the script
    # multiple times, until *something* releases the file.
    10.times do
      begin
        LXC.run_command([opts[:script]] + opts[:args])
        break
      rescue LXC::Error
        sleep(0.1)
      end
    end
  end

  _, status = Process.wait2(pid)
  ok(status.exitstatus)
end