Class: EY::Serverside::CLI

Inherits:
Thor show all
Defined in:
lib/engineyard-serverside/cli.rb

Constant Summary

Constants inherited from Thor

Thor::HELP_MAPPINGS, Thor::THOR_RESERVED_WORDS, Thor::VERSION

Instance Attribute Summary

Attributes included from Thor::Base

#options

Instance Method Summary collapse

Methods inherited from Thor

default_task, desc, handle_argument_error, #help, help, map, method_option, method_options, printable_tasks, start, task_help

Methods included from Thor::Base

included, #initialize, register_klass_file, shell, shell=, subclass_files, subclasses

Instance Method Details

#deploy(default_task = :deploy) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/engineyard-serverside/cli.rb', line 52

def deploy(default_task=:deploy)
  config = EY::Serverside::Deploy::Configuration.new(options)
  load_servers(config)

  EY::Serverside::LoggedOutput.verbose = options[:verbose]
  EY::Serverside::LoggedOutput.logfile = File.join(ENV['HOME'], "#{options[:app]}-deploy.log")

  invoke :propagate

  EY::Serverside::Deploy.new(config).send(default_task)
end

#hook(hook_name) ⇒ Object



88
89
90
# File 'lib/engineyard-serverside/cli.rb', line 88

def hook(hook_name)
  EY::Serverside::DeployHook.new(options).run(hook_name)
end

#install_bundler(version) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/engineyard-serverside/cli.rb', line 192

def install_bundler(version)
  egrep_escaped_version = version.gsub(/\./, '\.')
  # the grep "bundler " is so that gems like bundler08 don't get
  # their versions considered too
  #
  # the [,$] is to stop us from looking for e.g. 0.9.2, seeing
  # 0.9.22, and mistakenly thinking 0.9.2 is there
  has_bundler_cmd = "gem list bundler | grep \"bundler \" | egrep -q '#{egrep_escaped_version}[,)]'"

  unless system(has_bundler_cmd)
    system("gem install bundler -q --no-rdoc --no-ri -v '#{version}'")
  end
end

#integrateObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/engineyard-serverside/cli.rb', line 122

def integrate
  EY::Serverside::LoggedOutput.verbose = options[:verbose]
  EY::Serverside::LoggedOutput.logfile = File.join(ENV['HOME'], "#{options[:app]}-integrate.log")

  app_dir = Pathname.new "/data/#{options[:app]}"
  current_app_dir = app_dir + "current"

  # so that we deploy to the same place there that we have here
  integrate_options = options.dup
  integrate_options[:release_path] = current_app_dir.realpath.to_s

  # we have to deploy the same SHA there as here
  integrate_options[:branch] = (current_app_dir + 'REVISION').read.strip

  config = EY::Serverside::Deploy::Configuration.new(integrate_options)

  load_servers(config)

  invoke :propagate

  EY::Serverside::Server.all.each do |server|
    server.sync_directory app_dir
    # we're just about to recreate this, so it has to be gone
    # first. otherwise, non-idempotent deploy hooks could screw
    # things up, and since we don't control deploy hooks, we must
    # assume the worst.
    server.run("rm -rf #{current_app_dir}")
  end

  # deploy local-ref to other instances into /data/$app/local-current
  EY::Serverside::Deploy.new(config).cached_deploy
end

#propagateObject



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/engineyard-serverside/cli.rb', line 207

def propagate
  config          = EY::Serverside::Deploy::Configuration.new
  gem_filename    = "engineyard-serverside-#{EY::Serverside::VERSION}.gem"
  local_gem_file  = File.join(Gem.dir, 'cache', gem_filename)
  remote_gem_file = File.join(Dir.tmpdir, gem_filename)
  gem_binary      = File.join(Gem.default_bindir, 'gem')

  servers = EY::Serverside::Server.all.find_all { |server| !server.local? }

  futures = EY::Serverside::Future.call(servers) do |server|
    egrep_escaped_version = EY::Serverside::VERSION.gsub(/\./, '\.')
    # 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
    has_gem_cmd = "#{gem_binary} list engineyard-serverside | grep \"engineyard-serverside\" | egrep -q '#{egrep_escaped_version}[,)]'"

    if !server.run(has_gem_cmd)  # doesn't have this exact version
      puts "~> Installing engineyard-serverside on #{server.hostname}"

      system(Escape.shell_command([
        'scp', '-i', "#{ENV['HOME']}/.ssh/internal",
        "-o", "StrictHostKeyChecking=no",
        local_gem_file,
       "#{config.user}@#{server.hostname}:#{remote_gem_file}",
      ]))
      server.run("sudo #{gem_binary} install --no-rdoc --no-ri '#{remote_gem_file}'")
    end
  end

  EY::Serverside::Future.success?(futures)
end

#restartObject



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/engineyard-serverside/cli.rb', line 179

def restart
  EY::Serverside::LoggedOutput.verbose = options[:verbose]
  EY::Serverside::LoggedOutput.logfile = File.join(ENV['HOME'], "#{options[:app]}-restart.log")

  config = EY::Serverside::Deploy::Configuration.new(options)
  load_servers(config)

  invoke :propagate

  EY::Serverside::Deploy.new(config).restart_with_maintenance_page
end