Class: GitPusshuTen::Commands::Redis

Inherits:
Base
  • Object
show all
Defined in:
lib/gitpusshuten/modules/redis/command.rb

Instance Attribute Summary

Attributes inherited from Base

#cli, #command, #configuration, #environment, #hooks, #perform_hooks

Instance Method Summary collapse

Methods inherited from Base

#c, #command_object, description, #e, #error, example, #g, #git, #help, #local, long_description, #message, #perform!, #perform_hooks!, #post_perform!, #pre_perform!, #prompt_for_root_password!, #prompt_for_user_password!, #r, #requires_user_existence!, #silent, #standard, usage, #validate!, #warning, #y, #yes?

Constructor Details

#initialize(*objects) ⇒ Redis

Returns a new instance of Redis.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gitpusshuten/modules/redis/command.rb', line 11

def initialize(*objects)
  super
  
  @command = cli.arguments.shift
  
  help if command.nil? or e.name.nil?
  
  ##
  # Default Configuration
  @installation_dir           = "/etc/redis"
  @configuration_dir          = @installation_dir
  @configuration_file         = File.join(@configuration_dir, 'redis.conf')
  @local_configuration_dir    = File.join(local.gitpusshuten_dir, 'redis')
  @local_configuration_file   = File.join(@local_configuration_dir, "redis.conf")  
end

Instance Method Details

#download_redis_configuration_from_server!Object



74
75
76
77
78
79
80
# File 'lib/gitpusshuten/modules/redis/command.rb', line 74

def download_redis_configuration_from_server!
  FileUtils.mkdir_p(@local_configuration_dir)
  Spinner.return :message => "Downloading redis configuration from the server.." do
    e.scp_as_root(:download, @configuration_file, "#{@local_configuration_file}")
    g("Finished downloading!")
  end
end

#perform_install!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gitpusshuten/modules/redis/command.rb', line 27

def perform_install!
  if e.installed?('redis-server')
    error "Redis is already installed."
    exit
  end
  message "Going to install Redis Key-Value store systemwide"
  Spinner.return :message => "Installing #{y('Redis')}.." do
    e.install!("redis-server")
    g('Done!')
  end
  
  create_file = true
  if File.exist?(@local_configuration_file)
    warning "#{y( @local_configuration_file)} already exists, do you want to overwrite it?"
    create_file = yes?
  end  
  if create_file
    download_redis_configuration_from_server!
    message "The redis configuration has been downloaded to#{y( @local_configuration_file)}."
  end
end

#perform_upload_config!Object

Alias to perform_upload_configuration!



70
71
72
# File 'lib/gitpusshuten/modules/redis/command.rb', line 70

def perform_upload_config!
  perform_upload_configuration!
end

#perform_upload_configuration!Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gitpusshuten/modules/redis/command.rb', line 49

def perform_upload_configuration!
  unless e.directory?(@installation_dir)
    error "Could not find the Redis installation directory in #{y(@installation_dir)}"
    perform_install!
    exit
  end
  
  unless File.exist?(@local_configuration_file)
    error "Could not find the local Redis configuration file in #{y(@local_configuration_file)}"
    download_redis_configuration_from_server!
    message "Redis configuration has been fetched from the server, edit it and upload it again."
    exit
  end
  Spinner.return :message => "Uploading Redis configuration file #{y(@local_configuration_file)}.." do
    e.scp_as_root(:upload, @local_configuration_file, @configuration_dir)
    g('Done!')
  end
end