Sha256: 8e09f0ed6987c612533542a0475b6d281b79975aab5ff371cbec899feb18499b

Contents?: true

Size: 1.39 KB

Versions: 14

Compression:

Stored size: 1.39 KB

Contents

module Chake

  class Backend < Struct.new(:node)

    class CommandFailed < Exception
    end

    def scp
      ['scp']
    end

    def scp_dest
      ''
    end

    def rsync
      ['rsync']
    end

    def rsync_dest
      node.path + '/'
    end

    def run(cmd)
      printf "%#{Node.max_node_name_length}s: $ %s\n", node.hostname, cmd
      output = IO.popen(command_runner + [cmd])
      output.each_line do |line|
        printf "%#{Node.max_node_name_length}s: %s\n", node.hostname, line.strip
      end
      output.close
      if $?
        status = $?.exitstatus
        if status != 0
          raise CommandFailed.new([node.hostname, 'FAILED with exit status %d' % status].join(': '))
        end
      end
    end

    def run_shell
      system(*shell_command)
    end

    def run_as_root(cmd)
      if node.remote_username == 'root'
        run(cmd)
      else
        run('sudo ' + cmd)
      end
    end

    def to_s
      self.class.backend_name
    end

    def skip?
      false
    end

    def self.backend_name
      name.split("::").last.downcase
    end

    def self.inherited(subclass)
      @backends ||= []
      @backends << subclass
    end

    def self.get(name)
      backend = @backends.find { |b| b.backend_name == name }
      backend || raise(ArgumentError.new("Invalid backend name: #{name}"))
    end

  end

end

require 'chake/backend/ssh'
require 'chake/backend/local'

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
chake-0.15 lib/chake/backend.rb
chake-0.14 lib/chake/backend.rb
chake-0.13 lib/chake/backend.rb
chake-0.12 lib/chake/backend.rb
chake-0.11 lib/chake/backend.rb
chake-0.10.2 lib/chake/backend.rb
chake-0.10.1 lib/chake/backend.rb
chake-0.10 lib/chake/backend.rb
chake-0.9.1 lib/chake/backend.rb
chake-0.9 lib/chake/backend.rb
chake-0.8 lib/chake/backend.rb
chake-0.7 lib/chake/backend.rb
chake-0.6 lib/chake/backend.rb
chake-0.5 lib/chake/backend.rb