Class: Specinfra::Backend::Jexec

Inherits:
Exec
  • Object
show all
Defined in:
lib/specinfra/backend/jexec.rb

Instance Method Summary collapse

Methods inherited from Exec

#run_command

Methods inherited from Base

clear, #command, #get_config, #host_inventory, instance, #os_info, #set_config, #set_example, #stderr_handler=, #stdout_handler=

Constructor Details

#initialize(config = {}) ⇒ Jexec

Returns a new instance of Jexec.



4
5
6
7
8
9
10
# File 'lib/specinfra/backend/jexec.rb', line 4

def initialize(config = {})
  super(config)
  jname = get_config(:jail_name)
  jroot = `jls -j #{jname} path`.strip
  fail 'fail to get jail path!' if jroot.to_s.empty?
  set_config(:jail_root, jroot)
end

Instance Method Details

#build_command(cmd) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/specinfra/backend/jexec.rb', line 22

def build_command(cmd)
  shell = get_config(:shell) || '/bin/sh'
  cmd = cmd.shelljoin if cmd.is_a?(Array)
  shell = shell.shellescape

  if get_config(:interactive_shell)
    shell << " -i"
  end

  if get_config(:login_shell)
    shell << " -l"
  end

  cmd = "#{shell} -c #{cmd.to_s.shellescape}"

  path = get_config(:path)
  if path
    cmd = %Q{env PATH="#{path}" #{cmd}}
  end

  jname = get_config(:jail_name)
  "jexec #{jname} #{cmd}"
end

#send_directory(from, to) ⇒ Object



17
18
19
20
# File 'lib/specinfra/backend/jexec.rb', line 17

def send_directory(from, to)
  jroot = get_config(:jail_root)
  FileUtils.cp_r(from, "#{jroot}/#{to}")
end

#send_file(from, to) ⇒ Object



12
13
14
15
# File 'lib/specinfra/backend/jexec.rb', line 12

def send_file(from, to)
  jroot = get_config(:jail_root)
  FileUtils.cp(from, "#{jroot}/#{to}")
end