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, forward_agent: false, remote_forward: nil) ⇒ StackCommand

Returns a new instance of StackCommand.



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

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

Instance Method Details

#consoleObject



20
21
22
# File 'lib/omc/stack_command.rb', line 20

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

#dbObject



24
25
26
# File 'lib/omc/stack_command.rb', line 24

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



16
17
18
# File 'lib/omc/stack_command.rb', line 16

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

#ssh_and_execute(command) ⇒ Object



52
53
54
55
56
57
# File 'lib/omc/stack_command.rb', line 52

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

  exec 'ssh', *args
end

#status(thor) ⇒ Object



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

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



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

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