Class: EY::Serverside::Propagator
- Defined in:
- lib/engineyard-serverside/propagator.rb
Overview
Put the same engineyard-serverside on all the servers
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ Object
Find the servers that need the gem, then install the gem on them.
-
#check_command ⇒ Object
the [,)] is to stop us from looking for e.g.
- #count_servers(set) ⇒ Object
- #find_servers_missing_gem ⇒ Object
- #gem_binary ⇒ Object
-
#initialize(servers, config, shell, options = {}) ⇒ Propagator
constructor
A new instance of Propagator.
- #install_command ⇒ Object
- #propagate ⇒ Object
- #remote_gem_file ⇒ Object
- #scp_command(server) ⇒ Object
-
#servers ⇒ Object
servers that need to have the gem installed.
Constructor Details
#initialize(servers, config, shell, options = {}) ⇒ Propagator
Returns a new instance of Propagator.
13 14 15 16 |
# File 'lib/engineyard-serverside/propagator.rb', line 13 def initialize(servers, config, shell, ={}) @remote_servers = servers.remote @config, @shell = config, shell end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/engineyard-serverside/propagator.rb', line 11 def config @config end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
11 12 13 |
# File 'lib/engineyard-serverside/propagator.rb', line 11 def shell @shell end |
Class Method Details
.call(*args) ⇒ Object
7 8 9 |
# File 'lib/engineyard-serverside/propagator.rb', line 7 def self.call(*args) new(*args).call end |
Instance Method Details
#call ⇒ Object
Find the servers that need the gem, then install the gem on them
24 25 26 |
# File 'lib/engineyard-serverside/propagator.rb', line 24 def call servers.any? && propagate end |
#check_command ⇒ Object
the [,)] is to stop us from looking for e.g. 0.5.1, seeing 0.5.11, and mistakenly thinking 0.5.1 is there
38 39 40 |
# File 'lib/engineyard-serverside/propagator.rb', line 38 def check_command %{#{gem_binary} list #{About.gem_name} | grep "#{About.gem_name}" | egrep -q "#{About.version.gsub(/\./, '\.')}[,)]"} end |
#count_servers(set) ⇒ Object
56 57 58 |
# File 'lib/engineyard-serverside/propagator.rb', line 56 def count_servers(set) "#{set.size} server#{set.size == 1 ? '' : 's'}" end |
#find_servers_missing_gem ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/engineyard-serverside/propagator.rb', line 60 def find_servers_missing_gem return @remote_servers if @remote_servers.empty? shell.status "Verifying #{About.name_with_version} on #{count_servers(@remote_servers)}." @remote_servers.select_in_parallel do |server| !shell.logged_system(server.command_on_server('sh -l -c', check_command)).success? end end |
#gem_binary ⇒ Object
32 33 34 |
# File 'lib/engineyard-serverside/propagator.rb', line 32 def gem_binary File.join(Gem.default_bindir, 'gem') end |
#install_command ⇒ Object
52 53 54 |
# File 'lib/engineyard-serverside/propagator.rb', line 52 def install_command "#{gem_binary} install --no-rdoc --no-ri '#{remote_gem_file}'" end |
#propagate ⇒ Object
68 69 70 71 72 |
# File 'lib/engineyard-serverside/propagator.rb', line 68 def propagate shell.status "Propagating #{About.name_with_version} to #{count_servers(servers)}." servers.run_on_each { |server| shell.logged_system(scp_command(server)) } servers.run_on_each { |server| shell.logged_system(server.command_on_server('sudo sh -l -c', install_command)) } end |
#remote_gem_file ⇒ Object
28 29 30 |
# File 'lib/engineyard-serverside/propagator.rb', line 28 def remote_gem_file File.join(Dir.tmpdir, About.gem_filename) end |
#scp_command(server) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/engineyard-serverside/propagator.rb', line 42 def scp_command(server) Escape.shell_command([ 'scp', '-i', config.paths.internal_key.to_s, "-o", "StrictHostKeyChecking=no", About.gem_file, "#{server.}:#{remote_gem_file}", ]) end |
#servers ⇒ Object
servers that need to have the gem installed
19 20 21 |
# File 'lib/engineyard-serverside/propagator.rb', line 19 def servers @servers ||= find_servers_missing_gem end |