Class: Omc::StackCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/omc/stack_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(aws_account, user, stack_name, app: nil, layer: nil) ⇒ StackCommand

Returns a new instance of StackCommand.



6
7
8
9
10
11
12
# File 'lib/omc/stack_command.rb', line 6

def initialize , user, stack_name, app: nil, layer: nil
  @aws_account = 
  @user = user
  @stack_name = stack_name
  @app_name = app
  @layer_name = layer
end

Instance Method Details

#consoleObject



18
19
20
# File 'lib/omc/stack_command.rb', line 18

def console
  ssh_and_execute_as_deploy "cd /srv/www/#{app[:shortname]}/current && RAILS_ENV=#{app[:attributes]['RailsEnv']} bundle exec rails c"
end

#dbObject



22
23
24
# File 'lib/omc/stack_command.rb', line 22

def db
  ssh_and_execute_as_deploy "cd /srv/www/#{app[:shortname]}/current && RAILS_ENV=#{app[:attributes]['RailsEnv']} bundle exec rails db -p"
end

#sshObject



14
15
16
# File 'lib/omc/stack_command.rb', line 14

def ssh
  exec "ssh", *([ssh_host] + default_ssh_args)
end

#ssh_and_execute(command) ⇒ Object



50
51
52
53
54
55
# File 'lib/omc/stack_command.rb', line 50

def ssh_and_execute(command)
  puts "Executing '#{command}'"
  args = default_ssh_args + ['-t', ssh_host, command]

  exec 'ssh', *args
end

#status(thor) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/omc/stack_command.rb', line 35

def status(thor)
  details = stack.instances.map do |i|
    [
      i[:hostname],
      i[:instance_type],
      i[:status],
      i[:availability_zone],
      i[:ec2_instance_id],
      i[:public_ip],
      i[:private_ip],
    ]
  end
  thor.print_table(details)
end

#unicorn(action) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/omc/stack_command.rb', line 26

def unicorn(action)
  case action
  when "restart"
    stack.execute_recipes(app, recipes: ["deploy::rails-restart"], name: "restart")
  else
    abort("Unicorn action should be one of [restart]")
  end
end