Guest User

Untitled

a guest
May 7th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. begin
  2. require 'capistrano/recipes/deploy/strategy/fast_remote_cache'
  3. rescue LoadError
  4. require 'capistrano/recipes/deploy/strategy/remote_cache'
  5. end
  6.  
  7. module Capistrano
  8. module Deploy
  9. module Strategy
  10. RsyncRemoteCache = Class.new(defined?(FastRemoteCache) ? FastRemoteCache : RemoteCache)
  11.  
  12. class RsyncRemoteCache
  13. def deploy!
  14. logger.trace "deploying using #{'fast ' if FastRemoteCache === self}remote cache strategy"
  15. @only_primary = true
  16. super
  17. rsync_remote_cache
  18. end
  19.  
  20. def check!
  21. super.check do |check|
  22. check.remote.command('rsync')
  23. end
  24. end
  25.  
  26. protected :copy_repository_cache
  27.  
  28. def copy_repository_cache
  29. rsync_remote_cache
  30. @only_primary = false
  31. super
  32. end
  33.  
  34. def rsync_remote_cache
  35. logger.trace "rsyncing the cached version to #{repository_cache} on all servers"
  36.  
  37. primary_host = rsync_host(find_servers(:only => { :primary => true }).first)
  38. run_options = { :except => { :no_release => true, :primary => true } }
  39. cmd = []
  40. cmd << "ssh -o StrictHostKeyChecking=no #{primary_host} date"
  41. cmd << "rsync -a --delete #{primary_host}:#{repository_cache}/ #{repository_cache}/"
  42. run(cmd.join(' && '), run_options)
  43. end
  44.  
  45. def run(cmd, options = {}, &block)
  46. options[:only] = { :primary => true } if @only_primary && !options[:except]
  47. super(cmd, options, &block)
  48. end
  49.  
  50. def rsync_host(server)
  51. configuration[:user] ? "#{configuration[:user]}@#{server.host}" : server.host
  52. end
  53. end
  54. end
  55. end
  56. end
Add Comment
Please, Sign In to add comment