Class: Chake::Backend
- Inherits:
-
Struct
- Object
- Struct
- Chake::Backend
- Defined in:
- lib/chake/backend.rb,
lib/chake/backend/ssh.rb,
lib/chake/backend/local.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#node ⇒ Object
Returns the value of attribute node.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#node ⇒ Object
Returns the value of attribute node
3 4 5 |
# File 'lib/chake/backend.rb', line 3 def node @node end |
Class Method Details
.backend_name ⇒ Object
36 37 38 |
# File 'lib/chake/backend.rb', line 36 def self.backend_name name.split("::").last.downcase end |
.get(name) ⇒ Object
45 46 47 48 |
# File 'lib/chake/backend.rb', line 45 def self.get(name) backend = @backends.find { |b| b.backend_name == name } backend || raise(ArgumentError.new("Invalid backend name: #{name}")) end |
.inherited(subclass) ⇒ Object
40 41 42 43 |
# File 'lib/chake/backend.rb', line 40 def self.inherited(subclass) @backends ||= [] @backends << subclass end |
Instance Method Details
#rsync_dest ⇒ Object
5 6 7 |
# File 'lib/chake/backend.rb', line 5 def rsync_dest node.path + '/' end |
#run(cmd) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/chake/backend.rb', line 9 def run(cmd) puts "#{node.hostname}: $ #{cmd}" output = IO.popen(command_runner + [cmd]) output.each_line do |line| puts [node.hostname, line.strip].join(': ') end output.close if $? status = $?.exitstatus if status != 0 puts [node.hostname, 'FAILED with exit status %d' % status].join(': ') end end end |
#run_as_root(cmd) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/chake/backend.rb', line 24 def run_as_root(cmd) if node.username == 'root' run(cmd) else run('sudo sh -c "' + cmd + '"') end end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/chake/backend.rb', line 32 def to_s self.class.backend_name end |