diff options
author | Christian Poessinger <christian@poessinger.com> | 2019-10-23 05:46:34 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2019-10-23 05:47:09 +0200 |
commit | 760ac992c827734032cc41a77ba21bcc4bde50e1 (patch) | |
tree | d85e3e3092e04d146fd8c74ff3a127ef01140f75 /src | |
parent | 564c75c511c2cfd23404a500340a53441c694ffd (diff) | |
download | vyos-1x-760ac992c827734032cc41a77ba21bcc4bde50e1.tar.gz vyos-1x-760ac992c827734032cc41a77ba21bcc4bde50e1.zip |
ddclient: T1030: auto create runtime directories
Diffstat (limited to 'src')
-rwxr-xr-x | src/conf_mode/dynamic_dns.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/conf_mode/dynamic_dns.py b/src/conf_mode/dynamic_dns.py index d4e890ebb..3dc6857f9 100755 --- a/src/conf_mode/dynamic_dns.py +++ b/src/conf_mode/dynamic_dns.py @@ -23,14 +23,15 @@ from vyos import ConfigError config_file = r'/etc/ddclient/ddclient.conf' cache_file = r'/var/cache/ddclient/ddclient.cache' +pid_file = r'/var/run/ddclient/ddclient.pid' config_tmpl = """ ### Autogenerated by dynamic_dns.py ### daemon=1m syslog=yes ssl=yes -pid=/var/run/ddclient/ddclient.pid -cache=/var/cache/ddclient/ddclient.cache +pid={{ pid_file }} +cache={{ cache_file }} {% for interface in interfaces -%} @@ -89,6 +90,8 @@ default_service_protocol = { default_config_data = { 'interfaces': [], + 'cache_file': cache_file, + 'pid_file': pid_file } def get_config(): @@ -235,8 +238,15 @@ def generate(dyndns): if dyndns is None: return None - tmpl = jinja2.Template(config_tmpl) + dirname = os.path.dirname(dyndns['pid_file']) + if not os.path.exists(dirname): + os.mkdir(dirname) + + dirname = os.path.dirname(config_file) + if not os.path.exists(dirname): + os.mkdir(dirname) + tmpl = jinja2.Template(config_tmpl) config_text = tmpl.render(dyndns) with open(config_file, 'w') as f: f.write(config_text) @@ -244,11 +254,16 @@ def generate(dyndns): return None def apply(dyndns): - if os.path.exists(cache_file): - os.unlink(cache_file) + if os.path.exists(dyndns['cache_file']): + os.unlink(dyndns['cache_file']) + + if os.path.exists('/etc/ddclient.conf'): + os.unlink('/etc/ddclient.conf') if dyndns is None: os.system('/etc/init.d/ddclient stop') + if os.path.exists(dyndns['pid_file']): + os.unlink(dyndns['pid_file']) else: os.system('/etc/init.d/ddclient restart') |