INNER CODE UNIT · Python
detect_config_path
lebinh/ngxtop · ngxtop/config_parser.py:32
def detect_config_path():
"""
Get nginx configuration file path based on `nginx -V` output
:return: detected nginx configuration file path
"""
try:
proc = subprocess.Popen(['nginx', '-V'], stderr=subprocess.PIPE)
except OSError:
error_exit('Access log file or format was not set and nginx config file cannot be detected. ' +
'Perhaps nginx is not in your PATH?')
stdout, stderr = proc.communicate()
version_output = stderr.decode('utf-8')
conf_path_match = re.search(r'--conf-path=(\S*)', version_output)
if conf_path_match is not None:
return conf_path_match.group(1)
prefix_match = re.search(r'--prefix=(\S*)', version_output)