Module: PortMap::Nginx

Defined in:
lib/port_map/nginx.rb

Class Method Summary collapse

Class Method Details

.conf_directoryObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/port_map/nginx.rb', line 3

def self.conf_directory
  return ENV.fetch('NGINX_DIR') if ENV.key?('NGINX_DIR')

  _, stdout, stderr = Open3.popen3('nginx -t')
  location_match = [stdout.read, stderr.read].join.match(/nginx: the configuration file (.+?) syntax/)

  if location_match && !location_match.captures.empty?
    Pathname.new(location_match.captures.first).dirname.to_s
  else
    raise '`nginx -t` command did not reveal nginx conf. You can set NGINX_DIR environment variable to indicate nginx conf directory'
  end
end

.reloadObject



20
21
22
# File 'lib/port_map/nginx.rb', line 20

def self.reload
  `sudo nginx -s reload`
end

.servers_directoryObject



16
17
18
# File 'lib/port_map/nginx.rb', line 16

def self.servers_directory
  conf_directory + File::Separator + 'servers'
end