class Rundock::Backend::Base
Attributes
backend[R]
options[R]
Public Class Methods
new(options)
click to toggle source
# File lib/rundock/backend.rb, line 24 def initialize(options) @options = parse(options) @backend = create_specinfra_backend end
Public Instance Methods
run_commands(cmd, exec_options = {})
click to toggle source
# File lib/rundock/backend.rb, line 29 def run_commands(cmd, exec_options = {}) Array(cmd).each do |c| run_command(c, exec_options) end end
send_file(from, to)
click to toggle source
# File lib/rundock/backend.rb, line 35 def send_file(from, to) system("test -d #{from}") recursive = $?.to_i == 0 if !recursive @backend.send_file(from, to) else @backend.send_directory(from, to) end end
specinfra_run_command(command)
click to toggle source
# File lib/rundock/backend.rb, line 46 def specinfra_run_command(command) @backend.run_command(command) end
Private Instance Methods
create_specinfra_backend()
click to toggle source
# File lib/rundock/backend.rb, line 93 def create_specinfra_backend raise NotImplementedError end
host_inventory()
click to toggle source
# File lib/rundock/backend.rb, line 97 def host_inventory @backend.host_inventory end
method_missing(method, *args)
click to toggle source
# File lib/rundock/backend.rb, line 101 def method_missing(method, *args) @backend.send(method, *args) end
parse(options)
click to toggle source
# File lib/rundock/backend.rb, line 89 def parse(options) raise NotImplementedError end
run_command(cmd, exec_options = {})
click to toggle source
# File lib/rundock/backend.rb, line 52 def run_command(cmd, exec_options = {}) command = cmd.strip command = "sudo #{command.gsub(/^sudo +/, '')}" if exec_options[:sudo] command = "cd #{Shellwords.escape(exec_options[:cwd])} && #{command}" if exec_options[:cwd] command = "sudo -H -u #{Shellwords.escape(user)} -- /bin/sh -c #{command}" if exec_options[:user] Logger.debug(%(Start executing: "#{command}")) return nil if exec_options[:dry_run] begin result = @backend.run_command(command) rescue StandardError => e Logger.error(e.to_s) raise CommandResultStatusError if exec_options[:errexit] return nil end exit_status = result.exit_status Logger.formatter.indent do Logger.debug("cwd: #{exec_options[:cwd]}") if exec_options[:cwd] Logger.debug("sudo: #{exec_options[:sudo]}") if exec_options[:sudo] Logger.error(result.stderr.strip) unless result.stderr.strip.blank? Logger.info(result.stdout.strip) unless result.stdout.strip.blank? Logger.debug("errexit: #{exec_options[:errexit]}") Logger.debug("exit status: #{exit_status}") end Logger.formatter.simple_output(result.stdout.strip) if Logger.formatter.suppress_logging && !result.stdout.strip.blank? raise CommandResultStatusError if exec_options[:errexit] && exit_status != 0 result end