Class: Geordi::Remote
- Inherits:
-
Object
- Object
- Geordi::Remote
- Defined in:
- lib/geordi/remote.rb
Constant Summary collapse
- REMOTE_DUMP_PATH =
'~/dumps/dump_for_download.dump'.freeze
Instance Method Summary collapse
- #console(options = {}) ⇒ Object
- #dump(options = {}) ⇒ Object
-
#initialize(stage) ⇒ Remote
constructor
A new instance of Remote.
- #select_server ⇒ Object
- #shell(options = {}) ⇒ Object
Constructor Details
#initialize(stage) ⇒ Remote
Returns a new instance of Remote.
13 14 15 16 |
# File 'lib/geordi/remote.rb', line 13 def initialize(stage) @stage = stage @config = CapistranoConfig.new(stage) end |
Instance Method Details
#console(options = {}) ⇒ Object
55 56 57 |
# File 'lib/geordi/remote.rb', line 55 def console( = {}) shell(.merge(remote_command: Util.console_command(@config.env))) end |
#dump(options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/geordi/remote.rb', line 34 def dump( = {}) database = [:database] ? " #{[:database]}" : '' # Generate dump on the server shell .merge({ remote_command: "dumple #{@config.env}#{database} --for_download", }) destination_directory = File.join(@config.root, 'tmp') FileUtils.mkdir_p destination_directory destination_path = File.join(destination_directory, "#{@stage}.dump") relative_destination = Pathname.new(destination_path).relative_path_from Pathname.new(@config.root) Interaction.note "Downloading remote dump to #{relative_destination} ..." server = @config.primary_server Util.run!("scp -C #{@config.user(server)}@#{server}:#{REMOTE_DUMP_PATH} #{destination_path}") Interaction.success "Dumped the#{database} #{@stage} database to #{relative_destination}." destination_path end |
#select_server ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/geordi/remote.rb', line 18 def select_server selected_server = choose do || @config.servers.each do |server| .choice(server) { server } end # Default to the first listed server (by convention, the first server # in the deploy files is the primary one). .default = '1' .prompt = 'Connect to? [1] ' end puts selected_server end |
#shell(options = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/geordi/remote.rb', line 59 def shell( = {}) server_option = [:select_server] server_number = server_option.to_i server = if server_option == 'select_server' select_server elsif server_number != 0 && server_number <= @config.servers.count server_index = server_number - 1 @config.servers[server_index] elsif server_option.nil? @config.primary_server else Interaction.warn "Invalid server number: #{server_option}" select_server end remote_command = "cd #{@config.remote_root} && #{@config.shell}" remote_command << " -c '#{[:remote_command]}'" if [:remote_command] Interaction.note 'Connecting to ' + server.to_s Util.run!(['ssh', "#{@config.user(server)}@#{server}", '-t', remote_command]) end |