Class: ElasticsearchUpdate::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch_update/installer.rb

Overview

Installer

ElasticsearchUpdate::Installer class is used to install the downloaded Elasticsearch update file.

Parameters

Initilization requires a sudo password, file extension, and optional test parameter.

password is String. Ex. ‘test_password’

extension is String. Ex. ‘.deb’

test is a boolean identifying whether or not we are in a test if we are, we set the Logger to logging FATAL errors only.

Example

ElasticsearchUpdate::Installer.new('test_password', '.deb')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(password, extension, test = false) ⇒ Installer

initialize

Allows us to create an instance of the Installer.

Parameters

Initilization requires a sudo password, file extension, and optional test parameter.

password is String. Ex. ‘test_password’

extension is String. Ex. ‘.deb’

test is a boolean identifying whether or not we are in a test if we are, we set the Logger to logging FATAL errors only.

Example

ElasticsearchUpdate::Installer.new('test_password', '.deb')


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/elasticsearch_update/installer.rb', line 41

def initialize(password, extension, test = false)
  @log = Logger.new(STDOUT)
  if test
    @log.level = Logger::FATAL
  else
    @log.level = Logger::INFO
  end

  @log.debug('Logger created for Installer.')

  @sudo_password = password
  @extension = extension
end

Instance Attribute Details

#extensionObject

Returns the value of attribute extension.



23
24
25
# File 'lib/elasticsearch_update/installer.rb', line 23

def extension
  @extension
end

#sudo_passwordObject

Returns the value of attribute sudo_password.



23
24
25
# File 'lib/elasticsearch_update/installer.rb', line 23

def sudo_password
  @sudo_password
end

Instance Method Details

#install_file(file) ⇒ Object

install_file

Uses the extension found in the @extension variable set on initilization to determine what command should be used to install the update file.

Parameters

install_file requires the update file as a parameter.

file is File or Tempfile object. Ex. Tempfile.new(‘es_update_file’)

Example

install_file(Tempfile.new('es_update_file'))


68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/elasticsearch_update/installer.rb', line 68

def install_file(file)
  case @extension
  when '.zip'
    true
  when '.deb'
    install_update_file(file, @extension)
  when '.rpm'
    install_update_file(file, @extension)
  when '.tar.gz'
    true
  end
end

#install_update_file(file, extension) ⇒ Object

install_update_file

Uses the given file and extension to install the service version of Elasticsearch from an RPM or DEB file.

Parameters

install_update_file requires the update file and extension as a parameter.

file is File or Tempfile object. Ex. Tempfile.new(‘es_update_file’)

extension is String. Ex. ‘.deb’

Example

install_update_file(Tempfile.new('es_update_file'), '.deb')


96
97
98
99
100
101
102
103
104
105
106
# File 'lib/elasticsearch_update/installer.rb', line 96

def install_update_file(file, extension)
  @log.info('Installing' + extension + 'file.')
  command = 'echo ' + @sudo_password + ' | '
  case extension
  when '.deb'
    command += 'sudo -S dpkg -i "' + file.path + '"'
  when '.rpm'
    command += 'sudo -S rpm -i "' + file.path + '"'
  end
  Kernel.system(command)
end

#unzip_file(file) ⇒ Object

unzip_file

In development. Nothing occurs.



110
111
# File 'lib/elasticsearch_update/installer.rb', line 110

def unzip_file(file)
end