summaryrefslogtreecommitdiff
path: root/src/conf_mode/dynamic_dns.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-10-23 05:46:34 +0200
committerChristian Poessinger <christian@poessinger.com>2019-11-09 15:16:11 +0100
commita467fabbb5091783ebf7dd745ec7b90b847a900f (patch)
tree8ec135c6eae0e5714b437b099f5e1c37f133cbd1 /src/conf_mode/dynamic_dns.py
parent3a1f648943a25ffc4390dfeac15d0459f091edcc (diff)
downloadvyos-1x-a467fabbb5091783ebf7dd745ec7b90b847a900f.tar.gz
vyos-1x-a467fabbb5091783ebf7dd745ec7b90b847a900f.zip
ddclient: T1030: auto create runtime directories
(cherry picked from commit 760ac992c827734032cc41a77ba21bcc4bde50e1)
Diffstat (limited to 'src/conf_mode/dynamic_dns.py')
-rwxr-xr-xsrc/conf_mode/dynamic_dns.py25
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')