From 7068160b200d1d074f50f986edd3c1954fa96c73 Mon Sep 17 00:00:00 2001 From: Arano-kai Date: Thu, 14 Nov 2019 13:29:27 +0200 Subject: [PATCH] Systemd: move config generation to a separate unit - Modular unit composition: different tasks in separate units - Use systemd tool set to run checks - Avoid using inline shell in unit --- contrib/systemd/yggdrasil-default-config.service | 13 +++++++++++++ contrib/systemd/yggdrasil.service | 7 ++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 contrib/systemd/yggdrasil-default-config.service diff --git a/contrib/systemd/yggdrasil-default-config.service b/contrib/systemd/yggdrasil-default-config.service new file mode 100644 index 0000000..e9fe45b --- /dev/null +++ b/contrib/systemd/yggdrasil-default-config.service @@ -0,0 +1,13 @@ +[Unit] +Description=yggdrasil default config generator +ConditionPathExists=|!/etc/yggdrasil.conf +ConditionFileNotEmpty=|!/etc/yggdrasil.conf +Wants=local-fs.target +After=local-fs.target + +[Service] +Type=oneshot +Group=yggdrasil +StandardOutput=file:/etc/yggdrasil.conf +ExecStart=/usr/bin/yggdrasil -genconf +ExecStartPost=/usr/bin/chmod 0640 /etc/yggdrasil.conf diff --git a/contrib/systemd/yggdrasil.service b/contrib/systemd/yggdrasil.service index b48ff78..075c0bd 100644 --- a/contrib/systemd/yggdrasil.service +++ b/contrib/systemd/yggdrasil.service @@ -1,7 +1,9 @@ [Unit] Description=yggdrasil Wants=network.target +Wants=yggdrasil-default-config.service After=network.target +After=yggdrasil-default-config.service [Service] Group=yggdrasil @@ -10,11 +12,6 @@ ProtectSystem=true SyslogIdentifier=yggdrasil CapabilityBoundSet=CAP_NET_ADMIN ExecStartPre=+-/sbin/modprobe tun -ExecStartPre=/bin/sh -ec "if ! test -s /etc/yggdrasil.conf; \ - then umask 077; \ - yggdrasil -genconf > /etc/yggdrasil.conf; \ - echo 'WARNING: A new /etc/yggdrasil.conf file has been generated.'; \ - fi" ExecStart=/usr/bin/yggdrasil -useconffile /etc/yggdrasil.conf ExecReload=/bin/kill -HUP $MAINPID Restart=always