Sha256: 729f89e11808e8cd7cefc6639dbedae94b29fc68fb59508b3707878372153d16
Contents?: true
Size: 1.87 KB
Versions: 6
Compression:
Stored size: 1.87 KB
Contents
require 'engineyard-serverside/shell' module EY module Serverside class Task include EY::Serverside::Shell::Helpers attr_reader :config, :shell alias :c :config def initialize(conf, shell = nil) @config = conf @shell = shell @roles = :all end def require_custom_tasks deploy_file = ["config/eydeploy.rb", "eydeploy.rb"].map do |short_file| File.join(c.repository_cache, short_file) end.detect do |file| File.exist?(file) end if deploy_file shell.status "Loading deployment task overrides from #{deploy_file}" instance_eval(File.read(deploy_file)) true else false end end def roles(*task_roles) raise "Roles must be passed a block" unless block_given? begin @roles = task_roles yield ensure @roles = :all end end # Returns +true+ if the command is successful, # raises EY::Serverside::RemoteFailure with a list of failures # otherwise. def run(cmd, &blk) run_on_roles(cmd, &blk) end def sudo(cmd, &blk) run_on_roles(cmd, %w[sudo sh -l -c], &blk) end private def run_on_roles(cmd, wrapper=%w[sh -l -c], &block) servers = EY::Serverside::Server.from_roles(@roles) futures = EY::Serverside::Future.call(servers, block_given?) do |server, exec_block| to_run = exec_block ? block.call(server, cmd.dup) : cmd server.run(Escape.shell_command(wrapper + [to_run])) { |cmd| shell.logged_system(cmd) } end unless EY::Serverside::Future.success?(futures) failures = futures.select {|f| f.error? }.map {|f| f.inspect}.join("\n") raise EY::Serverside::RemoteFailure.new(failures) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems