diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-04-13 18:04:20 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-04-13 18:04:35 +0200 |
commit | 6185439442e8982febf6b8037a89fc2d7e6fa677 (patch) | |
tree | 8f89ff7b6d6a597077b7886a1e91c97423e89593 | |
parent | 1e6dc1a45dd113dc49d24738d0b324bb67a8d11f (diff) | |
download | vyos-1x-6185439442e8982febf6b8037a89fc2d7e6fa677.tar.gz vyos-1x-6185439442e8982febf6b8037a89fc2d7e6fa677.zip |
ddclient: T2185: migrate from SysVinit to systemd
-rw-r--r-- | data/templates/dynamic-dns/ddclient.conf.tmpl | 3 | ||||
-rwxr-xr-x | src/conf_mode/dynamic_dns.py | 33 | ||||
-rw-r--r-- | src/systemd/ddclient.service | 14 |
3 files changed, 22 insertions, 28 deletions
diff --git a/data/templates/dynamic-dns/ddclient.conf.tmpl b/data/templates/dynamic-dns/ddclient.conf.tmpl index 22cb38f4e..9c7219230 100644 --- a/data/templates/dynamic-dns/ddclient.conf.tmpl +++ b/data/templates/dynamic-dns/ddclient.conf.tmpl @@ -1,10 +1,7 @@ - ### Autogenerated by dynamic_dns.py ### daemon=1m syslog=yes ssl=yes -pid={{ pid_file }} -cache={{ cache_file }} {% for interface in interfaces -%} diff --git a/src/conf_mode/dynamic_dns.py b/src/conf_mode/dynamic_dns.py index b76503419..038f77cf9 100755 --- a/src/conf_mode/dynamic_dns.py +++ b/src/conf_mode/dynamic_dns.py @@ -25,10 +25,7 @@ from vyos import ConfigError from vyos.util import call from vyos.template import render - -config_file = r'/etc/ddclient/ddclient.conf' -cache_file = r'/var/cache/ddclient/ddclient.cache' -pid_file = r'/var/run/ddclient/ddclient.pid' +config_file = r'/run/ddclient/ddclient.conf' # Mapping of service name to service protocol default_service_protocol = { @@ -47,9 +44,7 @@ default_service_protocol = { default_config_data = { 'interfaces': [], - 'cache_file': cache_file, - 'deleted': False, - 'pid_file': pid_file + 'deleted': False } def get_config(): @@ -220,39 +215,27 @@ def verify(dyndns): def generate(dyndns): # bail out early - looks like removal from running config if dyndns['deleted']: - if os.path.exists(config_file): - os.unlink(config_file) - return None - 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) render(config_file, 'dynamic-dns/ddclient.conf.tmpl', dyndns) - + # Config file must be accessible only by its owner os.chmod(config_file, S_IRUSR | S_IWUSR) return None def apply(dyndns): - 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['deleted']: - call('/etc/init.d/ddclient stop') - if os.path.exists(dyndns['pid_file']): - os.unlink(dyndns['pid_file']) + call('systemctl stop ddclient.service') + if os.path.exists(config_file): + os.unlink(config_file) + else: - call('/etc/init.d/ddclient restart') + call('systemctl restart ddclient.service') return None diff --git a/src/systemd/ddclient.service b/src/systemd/ddclient.service new file mode 100644 index 000000000..a4d55827a --- /dev/null +++ b/src/systemd/ddclient.service @@ -0,0 +1,14 @@ +[Unit] +Description=Dynamic DNS Update Client +RequiresMountsFor=/run +ConditionPathExists=/run/ddclient/ddclient.conf +After=vyos-router.service + +[Service] +WorkingDirectory=/run/ddclient +Type=forking +PIDFile=/run/ddclient/ddclient.pid +ExecStart=/usr/sbin/ddclient -cache /run/ddclient/ddclient.cache -pid /run/ddclient/ddclient.pid -file /run/ddclient/ddclient.conf + +[Install] +WantedBy=multi-user.target |