]> git.ipfire.org Git - thirdparty/pdns.git/blame - dockerdata/startup.py
Merge pull request #14195 from rgacogne/ddist-no-assertions
[thirdparty/pdns.git] / dockerdata / startup.py
CommitLineData
aa665201 1#!/usr/bin/env -S python3 -u
c0e0545b
PD
2import os
3import sys
6c1e69e0 4import jinja2
c0e0545b
PD
5
6program = sys.argv[0].split('-')[0]
7product = os.path.basename(program)
8
c0e0545b
PD
9apienvvar = None
10apiconftemplate = None
6c1e69e0
PL
11templateroot = '/etc/powerdns/templates.d'
12templatedestination = ''
c0e0545b
PD
13args = []
14
15if product == 'pdns_recursor':
654b1265 16 args = ['--disable-syslog']
654b1265
PL
17 apienvvar = 'PDNS_RECURSOR_API_KEY'
18 apiconftemplate = """webserver
6c1e69e0 19api-key={{ apikey }}
c0e0545b
PD
20webserver-address=0.0.0.0
21webserver-allow-from=0.0.0.0/0
6c1e69e0 22webserver-password={{ apikey }}
654b1265 23 """
6c1e69e0 24 templatedestination = '/etc/powerdns/recursor.d'
c0e0545b 25elif product == 'pdns_server':
654b1265 26 args = ['--disable-syslog']
654b1265
PL
27 apienvvar = 'PDNS_AUTH_API_KEY'
28 apiconftemplate = """webserver
c0e0545b 29api
6c1e69e0 30api-key={{ apikey }}
c0e0545b
PD
31webserver-address=0.0.0.0
32webserver-allow-from=0.0.0.0/0
6c1e69e0 33webserver-password={{ apikey }}
654b1265 34 """
6c1e69e0 35 templatedestination = '/etc/powerdns/pdns.d'
c0e0545b 36elif product == 'dnsdist':
654b1265 37 args = ['--supervised', '--disable-syslog']
654b1265 38 apienvvar = 'DNSDIST_API_KEY'
fa8766c5 39 apiconftemplate = """webserver("0.0.0.0:8083")
b9e82a46 40 setWebserverConfig({password='{{ apikey }}', apiKey='{{ apikey }}', acl='0.0.0.0/0'})
c0e0545b 41controlSocket('0.0.0.0:5199')
6c1e69e0 42setKey('{{ apikey }}')
c0e0545b 43setConsoleACL('0.0.0.0/0')
654b1265 44 """
6c1e69e0
PL
45 templateroot = '/etc/dnsdist/templates.d'
46 templatedestination = '/etc/dnsdist/conf.d'
c0e0545b 47
d773b7bb
CD
48debug = os.getenv("DEBUG_CONFIG", 'no').lower() == 'yes'
49
c0e0545b 50apikey = os.getenv(apienvvar)
c0e0545b 51if apikey is not None:
6c1e69e0
PL
52 webserver_conf = jinja2.Template(apiconftemplate).render(apikey=apikey)
53 conffile = os.path.join(templatedestination, '_api.conf')
54 with open(conffile, 'w') as f:
55 f.write(webserver_conf)
d773b7bb
CD
56 if debug:
57 print("Created {} with content:\n{}\n".format(conffile, webserver_conf))
6c1e69e0
PL
58
59templates = os.getenv('TEMPLATE_FILES')
60if templates is not None:
61 for templateFile in templates.split(','):
62 template = None
63 with open(os.path.join(templateroot, templateFile + '.j2')) as f:
64 template = jinja2.Template(f.read())
65 rendered = template.render(os.environ)
f51f65eb
PL
66 target = os.path.join(templatedestination, templateFile + '.conf')
67 with open(target, 'w') as f:
6c1e69e0 68 f.write(rendered)
d773b7bb
CD
69 if debug:
70 print("Created {} with content:\n{}\n".format(target, rendered))
c0e0545b
PD
71
72os.execv(program, [program]+args+sys.argv[1:])