Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment