Class: Cloudkeeper::Nginx::HttpServer

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudkeeper/nginx/http_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHttpServer

Returns a new instance of HttpServer.



13
14
15
# File 'lib/cloudkeeper/nginx/http_server.rb', line 13

def initialize
  @access_data = {}
end

Instance Attribute Details

#access_dataObject (readonly)

Returns the value of attribute access_data.



11
12
13
# File 'lib/cloudkeeper/nginx/http_server.rb', line 11

def access_data
  @access_data
end

#auth_fileObject (readonly)

Returns the value of attribute auth_file.



11
12
13
# File 'lib/cloudkeeper/nginx/http_server.rb', line 11

def auth_file
  @auth_file
end

#conf_fileObject (readonly)

Returns the value of attribute conf_file.



11
12
13
# File 'lib/cloudkeeper/nginx/http_server.rb', line 11

def conf_file
  @conf_file
end

Instance Method Details

#start(image_file) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cloudkeeper/nginx/http_server.rb', line 17

def start(image_file)
  logger.debug 'Starting NGINX server'
  @access_data = {}
  credentials = prepare_credentials
  configuration = prepare_configuration File.dirname(image_file), File.basename(image_file)
  prepare_configuration_file configuration
  fill_access_data credentials, configuration

  Cloudkeeper::CommandExecutioner.execute Cloudkeeper::Settings[:'nginx-binary'],
                                          '-c', conf_file.path,
                                          '-p', Cloudkeeper::Settings[:'nginx-runtime-dir']
rescue Cloudkeeper::Errors::CommandExecutionError, ::IOError => ex
  stop
  raise Cloudkeeper::Errors::NginxError, ex
end

#stopObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cloudkeeper/nginx/http_server.rb', line 33

def stop
  logger.debug 'Stopping NGINX server'
  if conf_file
    Cloudkeeper::CommandExecutioner.execute Cloudkeeper::Settings[:'nginx-binary'],
                                            '-s', 'stop',
                                            '-c', conf_file.path,
                                            '-p', Cloudkeeper::Settings[:'nginx-runtime-dir']
    conf_file.unlink
  end

  auth_file.unlink if auth_file
  @access_data = {}
rescue Cloudkeeper::Errors::CommandExecutionError, ::IOError => ex
  raise Cloudkeeper::Errors::NginxError, ex
end