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

#initialize ⇒ HttpServer

Returns a new instance of HttpServer.



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

def initialize
  @access_data = {}
end

Instance Attribute Details

#access_data ⇒ Object (readonly)

Returns the value of attribute access_data.



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

def access_data
  @access_data
end

#auth_file ⇒ Object (readonly)

Returns the value of attribute auth_file.



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

def auth_file
  @auth_file
end

#conf_file ⇒ Object (readonly)

Returns the value of attribute conf_file.



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

def conf_file
  @conf_file
end

Instance Method Details

#start(image_file) ⇒ Object



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

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
rescue Cloudkeeper::Errors::CommandExecutionError, ::IOError => ex
  stop
  raise Cloudkeeper::Errors::NginxError, ex
end

#stop ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cloudkeeper/nginx/http_server.rb', line 30

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

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