Skip to content

Instantly share code, notes, and snippets.

@seiji
Created April 15, 2014 03:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save seiji/10700735 to your computer and use it in GitHub Desktop.
upload rsync with capistrano
module ::Capistrano
class Configuration
module Actions
module Rsync
def self.included(base)
base.send(:alias_method, :old_upload, :upload)
base.send(:alias_method, :upload, :new_upload)
end
def new_upload(from, to)
servers = find_servers_for_task(current_task, {})
raise Capistrano::NoMatchingServersError if servers.empty?
servers.each do |server|
begin
u = server.user || exists?(:user) ? fetch(:user) : nil
dest = "#{server.host}:#{to}"
if not u.nil?
dest = "#{u}@#{dest}"
end
system_or_exit(%Q[rsync --progress -avz #{from} #{dest}])
rescue => error
raise unless current_task && current_task.continue_on_error?
end
end
end
private
def system_or_exit(cmd, stdout = nil)
puts "$ #{cmd}"
cmd += " >#{stdout}" if stdout
system(cmd) or raise "command failed. "
end
end
end
end
end
Capistrano::Configuration.send(:include, Actions::Rsync)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment