Class: OsCtld::ContainerControl::Commands::Mount::Runner

Inherits:
Runner
  • Object
show all
Defined in:
lib/osctld/container_control/commands/mount.rb

Instance Attribute Summary

Attributes inherited from Runner

#ctid, #log_file, #lxc_home, #user_home

Instance Method Summary collapse

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(opts) ⇒ Object

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :shared_dir (String)

    path to the host-shared directory

  • :src (String)

    directory inside `:shared_dir` to relocate

  • :dst (String)

    target mountpoint



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
64
65
66
67
68
69
70
71
72
73
# File 'lib/osctld/container_control/commands/mount.rb', line 25

def execute(opts)
  ct = lxc_ct
  r, w = IO.pipe

  pid = ct.attach(stdout: w) do
    r.close

    begin
      src = File.join(opts[:shared_dir], opts[:src])

      if !Dir.exist?(opts[:shared_dir])
        puts "error:Shared dir not found at: #{opts[:shared_dir]}"

      elsif !Dir.exist?(src)
        puts "error:Source directory not found at: #{src}"

      else
        FileUtils.mkpath(opts[:dst])
        Mount::Sys.move_mount(src, opts[:dst])
        puts 'ok:done'
      end

    rescue => e
      puts "error:Exception (#{e.class}): #{e.message}"

    ensure
      STDOUT.flush
    end
  end

  w.close

  line = r.readline
  Process.wait(pid)
  r.close
  log(:warn, ct, "Mounter exited with #{$?.exitstatus}") if $?.exitstatus != 0

  i = line.index(':')
  return error("invalid return value: #{line.inspect}") unless i

  status = line[0..i-1]
  msg = line[i+1..-1]

  if status == 'ok'
    ok
  else
    error(msg)
  end
end