Module: Deployku::Containerable

Included in:
AppPlugin, PostgresPlugin, RedisPlugin
Defined in:
lib/deployku/containerable.rb

Instance Method Summary collapse

Instance Method Details

#container_id_path(app_name) ⇒ Object



41
42
43
# File 'lib/deployku/containerable.rb', line 41

def container_id_path(app_name)
  File.join(dir(app_name), 'CONTAINER_ID')
end

#get_container_id(app_name) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/deployku/containerable.rb', line 45

def get_container_id(app_name)
  container_hash_path = container_id_path(app_name)
  if File.exists?(container_hash_path)
    File.read(container_hash_path)
  else
    nil
  end
end

#get_status(app_name) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/deployku/containerable.rb', line 74

def get_status(app_name)
  cid = get_container_id(app_name)
  if cid
    Deployku::Engine.running?(cid)
  else
    nil
  end
end

#logs(app_name) ⇒ Object



34
35
36
37
38
# File 'lib/deployku/containerable.rb', line 34

def logs(app_name)
  Deployku::Config.load(config_path(app_name))
  app_hash = get_container_id(app_name)
  Deployku::Engine.logs(app_hash)
end

#restart(app_name) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/deployku/containerable.rb', line 26

def restart(app_name)
  old_cid = get_container_id(app_name)
  if start(app_name)
    # stops old application only if new instance was spawn
    stop(app_name, cid: old_cid) if old_cid
  end
end

#run(app_name, *cmd) ⇒ Object



11
12
13
14
15
16
# File 'lib/deployku/containerable.rb', line 11

def run(app_name, *cmd)
  Deployku::Config.load(config_path(app_name))
  app_name = Deployku.sanitize_app_name(app_name)
  Deployku::Engine.run(app_name, dir(app_name), *cmd)
  exit 1 if $?.nil? || $?.exitstatus != 0
end

#set_container_id(app_name, hash) ⇒ Object



54
55
56
57
58
59
# File 'lib/deployku/containerable.rb', line 54

def set_container_id(app_name, hash)
  container_hash_path = container_id_path(app_name)
  File.open(container_hash_path, 'w') do |f|
    f << hash
  end
end

#start(app_name) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/deployku/containerable.rb', line 2

def start(app_name)
  Deployku::Config.load(config_path(app_name))
  app_name = Deployku.sanitize_app_name(app_name)
  app_hash = Deployku::Engine.start(app_name, dir(app_name))
  exit 1 if $?.nil? || $?.exitstatus != 0
  set_container_id(app_name, app_hash)
  puts "Container #{app_hash} started."
end

#status(app_name) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/deployku/containerable.rb', line 61

def status(app_name)
  s = get_status(app_name)
  if s == nil
    puts 'Container does not exist.'
  else
    if s == true
      puts 'Container is running.'
    else
      puts 'Container is not running.'
    end
  end
end

#stop(app_name, cid: nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/deployku/containerable.rb', line 18

def stop(app_name, cid: nil)
  Deployku::Config.load(config_path(app_name))
  app_hash = cid ? cid : get_container_id(app_name)
  if app_hash
    Deployku::Engine.stop(app_hash)
  end
end