Class: PsRemoveCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/ukku/ps_remove_command.rb

Instance Method Summary collapse

Instance Method Details

#execute(args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ukku/ps_remove_command.rb', line 2

def execute(args)
  type = args['TYPE']

  if !File.exist?(UKKU_FILE)
    raise "No application configured. Run 'ukku configure HOST' first."
  end

  data = YAML.load_file(UKKU_FILE)
  name, server = data.first
  if name.nil?
    raise "No application configured. Run 'ukku configure <host>' first."
  end

  if data.length > 1
    if args['--app'].empty?
      raise "No app specified, use the --app NAME option"
    else
      name = args[--app]
      sever = data[name]
    end
  end

  host = server['host']
  user = server['user']
  identity_file = server['identity_file']

  puts "Removing process type '#{type}' on #{host} ..."
  conn = Connection.new(host, user, identity_file)
  conn.execute("sudo rm /etc/ukku/ps-types/#{type} && docker kill app-#{type} && docker rm app-#{type}")
  begin
    conn.execute("launchapp")
  rescue Subprocess::NonZeroExit => e
  end
end