Class: Deployku::RedisPlugin

Inherits:
Plugin
  • Object
show all
Includes:
Configurable, Containerable
Defined in:
lib/deployku/plugins/redis.rb

Instance Attribute Summary

Attributes included from Configurable

#config

Instance Method Summary collapse

Methods included from Containerable

#container_id_path, #get_container_id, #get_status, #logs, #run, #set_container_id, #status, #stop

Methods included from Configurable

#config_load, #config_path, #config_save, #config_set, #config_set_engine, #config_set_from, #config_set_port, #config_show, #config_unset, #config_unset_engine, #config_unset_from, #config_unset_port

Methods inherited from Plugin

<<, command_description, filter_plugins, find_plugin, help, inherited, instance, #packages, run

Constructor Details

#initializeRedisPlugin

Returns a new instance of RedisPlugin.



9
10
11
12
13
14
# File 'lib/deployku/plugins/redis.rb', line 9

def initialize
  @config = {
    'from' => 'redis',
    'env' => {}
  }
end

Instance Method Details

#container_name(app_name) ⇒ Object



91
92
93
# File 'lib/deployku/plugins/redis.rb', line 91

def container_name(app_name)
  "deployku-redis-#{Deployku.sanitize_app_name(app_name)}"
end

#create(name) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/deployku/plugins/redis.rb', line 17

def create(name)
  app_dir = dir(name)
  unless Dir.exists?(app_dir)
    FileUtils.mkdir_p(app_dir)
  end
  app_dir
end

#delete(name) ⇒ Object



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

def delete(name)
  app_dir = dir(name)
  if Dir.exists?(app_dir)
    FileUtils.rm_rf(app_dir)
  end
end

#dir(name) ⇒ Object



87
88
89
# File 'lib/deployku/plugins/redis.rb', line 87

def dir(name)
  File.join(Deployku::Config.home, '.redis', Deployku.sanitize_app_name(name))
end


41
42
43
44
45
46
47
# File 'lib/deployku/plugins/redis.rb', line 41

def link(name, app_name)
  config_load(name)
  redis_id = get_container_id(name)
  redis_url = "redis://#{container_name(name)}:6379/"
  Deployku::AppPlugin.run('config:set', [app_name, 'REDIS_URL', redis_url])
  Deployku::AppPlugin.run(:link, [app_name, container_name(name)])
end

#listObject



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

def list
  Dir.glob(File.join(Deployku::Config.home, '.redis', '*')) do |path|
    puts File.basename(path) if File.directory?(path)
  end
end

#restart(app_name) ⇒ Object



70
71
72
73
74
# File 'lib/deployku/plugins/redis.rb', line 70

def restart(app_name)
  # restart can not be done seamlessly because we use named containers
  stop(app_name)
  start(app_name)
end

#start(app_name) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/deployku/plugins/redis.rb', line 51

def start(app_name)
  config_load(app_name)
  unless @config['volumes']
    @config['volumes'] = {
      File.join(dir(app_name), 'redis') => '/data/'
    }
  end
  config_save(app_name)

  Deployku::Config.merge!(@config)
  app_hash = Deployku::Engine.start(@config['from'], dir(app_name), container_name(app_name))
  exit 1 if $?.nil? || $?.exitstatus != 0
  set_container_id(app_name, container_name(app_name))
  puts "Container #{app_hash} started."
end