Loading monitor.py +15 −1 Original line number Diff line number Diff line Loading @@ -78,10 +78,12 @@ def add_core_config(engine, opts): Add a minimal Nginx configuration """ template = engine.get_template('nginx.conf') context = opts.__dict__.copy() context['nameservers'] = set(get_nameservers()) with opts.nginx_directory as _dir: path = pathlib.Path(_dir) with path.joinpath('nginx.conf').open('w') as conf: conf.writelines(template.stream(**opts.__dict__)) conf.writelines(template.stream(**context)) path.joinpath('streams').mkdir(exist_ok=True) yield path Loading Loading @@ -375,6 +377,18 @@ def addr_from_names(names: Iterable[str]) -> Iterable[IPAddressTypes]: yield ipaddress.ip_address(addrinfo[0]) def get_nameservers(): with open('/etc/resolv.conf') as rc: for line in rc: line = line.strip() if not line or line[0] in '#;': continue opt, *args = line.split() if opt != 'nameserver': continue yield from ((a, 53) for a in args) if __name__ == '__main__': logging.basicConfig() logger = logging.getLogger('monitor') Loading templates/nginx.conf +1 −0 Original line number Diff line number Diff line Loading @@ -40,5 +40,6 @@ http { } stream { resolver {% for ns in nameservers %}{{ ns|nginx_addr }}{% endfor %} valid=10s; include {{ nginx_directory }}/streams/*.conf; } Loading
monitor.py +15 −1 Original line number Diff line number Diff line Loading @@ -78,10 +78,12 @@ def add_core_config(engine, opts): Add a minimal Nginx configuration """ template = engine.get_template('nginx.conf') context = opts.__dict__.copy() context['nameservers'] = set(get_nameservers()) with opts.nginx_directory as _dir: path = pathlib.Path(_dir) with path.joinpath('nginx.conf').open('w') as conf: conf.writelines(template.stream(**opts.__dict__)) conf.writelines(template.stream(**context)) path.joinpath('streams').mkdir(exist_ok=True) yield path Loading Loading @@ -375,6 +377,18 @@ def addr_from_names(names: Iterable[str]) -> Iterable[IPAddressTypes]: yield ipaddress.ip_address(addrinfo[0]) def get_nameservers(): with open('/etc/resolv.conf') as rc: for line in rc: line = line.strip() if not line or line[0] in '#;': continue opt, *args = line.split() if opt != 'nameserver': continue yield from ((a, 53) for a in args) if __name__ == '__main__': logging.basicConfig() logger = logging.getLogger('monitor') Loading
templates/nginx.conf +1 −0 Original line number Diff line number Diff line Loading @@ -40,5 +40,6 @@ http { } stream { resolver {% for ns in nameservers %}{{ ns|nginx_addr }}{% endfor %} valid=10s; include {{ nginx_directory }}/streams/*.conf; }