Skip to content

Instantly share code, notes, and snippets.

@kpumuk
Created May 12, 2010 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpumuk/398068 to your computer and use it in GitHub Desktop.
Save kpumuk/398068 to your computer and use it in GitHub Desktop.
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