class Chake::Backend
Public Class Methods
Source
# File lib/chake/backend.rb, line 61 def self.backend_name name.split("::").last.downcase end
Source
# File lib/chake/backend.rb, line 70 def self.get(name) backend = @backends.find { |b| b.backend_name == name } backend || raise(ArgumentError.new("Invalid backend name: #{name}")) end
Source
# File lib/chake/backend.rb, line 65 def self.inherited(subclass) @backends ||= [] @backends << subclass end
Public Instance Methods
Source
# File lib/chake/backend.rb, line 24 def run(cmd) printf "%#{Node.max_node_name_length}s: $ %s\n", node.hostname, cmd io = IO.popen(command_runner + ['/bin/sh'], mode='w+', eer: [:child, :out]) io.write(cmd) io.close_write io.each_line do |line| printf "%#{Node.max_node_name_length}s: %s\n", node.hostname, line.gsub(/\s*$/, '') end io.close if $? status = $?.exitstatus if status != 0 raise CommandFailed.new([node.hostname, 'FAILED with exit status %d' % status].join(': ')) end end end
Source
# File lib/chake/backend.rb, line 45 def run_as_root(cmd) if node.remote_username == 'root' run(cmd) else run('sudo ' + cmd) end end