Created
April 15, 2014 03:54
-
-
Save seiji/10700735 to your computer and use it in GitHub Desktop.
upload rsync with capistrano
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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