Class: EY::Serverside::CLI

Inherits:
Thor
  • Object
show all
Extended by:
CLIHelpers
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

#args, #options, #parent_options

Instance Method Summary collapse

Methods included from CLIHelpers

account_app_env_options, config_option, framework_env_option, instances_options, stack_option, verbose_option

Methods inherited from Thor

check_unknown_options!, check_unknown_options?, default_task, desc, help, #help, long_desc, map, method_option, method_options, printable_tasks, register, subcommand, subcommands, 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



48
49
50
51
52
# File 'lib/engineyard-serverside/cli.rb', line 48

def deploy(default_task=:deploy)
  init_and_propagate(options, default_task.to_s) do |servers, config, shell|
    EY::Serverside::Deploy.new(servers, config, shell).send(default_task)
  end
end

#disable_maintenanceObject



81
82
83
84
85
# File 'lib/engineyard-serverside/cli.rb', line 81

def disable_maintenance
  init_and_propagate(options, 'disable_maintenance') do |servers, config, shell|
    EY::Serverside::Maintenance.new(servers, config, shell).manually_disable
  end
end

#enable_maintenanceObject



59
60
61
62
63
# File 'lib/engineyard-serverside/cli.rb', line 59

def enable_maintenance
  init_and_propagate(options, 'enable_maintenance') do |servers, config, shell|
    EY::Serverside::Maintenance.new(servers, config, shell).manually_enable
  end
end

#hook(hook_name) ⇒ Object



101
102
103
104
105
# File 'lib/engineyard-serverside/cli.rb', line 101

def hook(hook_name)
  init(options, "hook-#{hook_name}") do |servers, config, shell|
    EY::Serverside::DeployHook.new(config, shell, hook_name).call
  end
end

#integrateObject



116
117
118
119
120
121
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
# File 'lib/engineyard-serverside/cli.rb', line 116

def integrate
  app_dir = Pathname.new "/data/#{options[:app]}"
  current_app_dir = app_dir.join("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.join('REVISION').read.strip

  # always rebundle gems on integrate to make sure the instance comes up correctly.
  integrate_options[:clean] = true

  logname = "integrate-#{options[:instances].join('-')}".gsub(/[^-.\w]/,'')

  init_and_propagate(integrate_options, logname) do |servers, config, shell|

    # We have to rsync the entire app dir, so we need all the permissions to be correct!
    chown_command = %|find #{app_dir} \\( -not -user #{config.user} -or -not -group #{config.group} \\) -exec chown -h #{config.user}:#{config.group} "{}" +|
    shell.logged_system("sudo sh -l -c '#{chown_command}'", servers.detect {|s| s.local?})

    servers.run_for_each! do |server|
      chown = server.command_on_server('sudo sh -l -c', chown_command)
      sync  = server.sync_directory_command(app_dir, options[:ignore_existing])
      clean = server.command_on_server('sh -l -c', "rm -rf #{current_app_dir}")
      "(#{chown}) && (#{sync}) && (#{clean})"
    end

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

#maintenance_statusObject



70
71
72
73
74
# File 'lib/engineyard-serverside/cli.rb', line 70

def maintenance_status
  init(options, "maintenance-status") do |servers, config, shell|
    EY::Serverside::Maintenance.new(servers, config, shell).status
  end
end

#restartObject



155
156
157
158
159
160
161
162
# File 'lib/engineyard-serverside/cli.rb', line 155

def restart
  options = self.options.dup
  options[:release_path] = Pathname.new("/data/#{options[:app]}/current").realpath.to_s

  init_and_propagate(options, 'restart') do |servers, config, shell|
    EY::Serverside::Deploy.new(servers, config, shell).restart_with_maintenance_page
  end
end