Created
May 12, 2010 00:54
-
-
Save kpumuk/398068 to your computer and use it in GitHub Desktop.
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
begin | |
require 'capistrano/recipes/deploy/strategy/fast_remote_cache' | |
rescue LoadError | |
require 'capistrano/recipes/deploy/strategy/remote_cache' | |
end | |
module Capistrano | |
module Deploy | |
module Strategy | |
RsyncRemoteCache = Class.new(defined?(FastRemoteCache) ? FastRemoteCache : RemoteCache) | |
class RsyncRemoteCache | |
def deploy! | |
logger.trace "deploying using #{'fast ' if FastRemoteCache === self}remote cache strategy" | |
@only_primary = true | |
super | |
rsync_remote_cache | |
end | |
def check! | |
super.check do |check| | |
check.remote.command('rsync') | |
end | |
end | |
protected :copy_repository_cache | |
def copy_repository_cache | |
rsync_remote_cache | |
@only_primary = false | |
super | |
end | |
def rsync_remote_cache | |
logger.trace "rsyncing the cached version to #{repository_cache} on all servers" | |
primary_host = rsync_host(find_servers(:only => { :primary => true }).first) | |
run_options = { :except => { :no_release => true, :primary => true } } | |
cmd = [] | |
cmd << "ssh -o StrictHostKeyChecking=no #{primary_host} date" | |
cmd << "rsync -a --delete #{primary_host}:#{repository_cache}/ #{repository_cache}/" | |
run(cmd.join(' && '), run_options) | |
end | |
def run(cmd, options = {}, &block) | |
options[:only] = { :primary => true } if @only_primary && !options[:except] | |
super(cmd, options, &block) | |
end | |
def rsync_host(server) | |
configuration[:user] ? "#{configuration[:user]}@#{server.host}" : server.host | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment