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, #stderr, #stdin, #stdout, #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

  • :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 (Hash)
  • :close_fds (Array<IO>)
  • :wait (Boolean)

Returns:

  • (Integer)

    exit status



106
107
108
# File 'lib/osctld/container_control/commands/runscript.rb', line 106

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

#runscript_run_network(opts) ⇒ Object (protected)



138
139
140
141
142
143
# File 'lib/osctld/container_control/commands/runscript.rb', line 138

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)



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/osctld/container_control/commands/runscript.rb', line 112

def runscript_running(opts)
  pid = lxc_ct.attach(
    stdin:,
    stdout:,
    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
      LXC.run_command([opts[:script]] + opts[:args])
      break
    rescue LXC::Error
      sleep(0.1)
    end
  end

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