From e447af8d355ab790c46df29083b6cf0da5fda9b5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 3 Dec 2019 10:17:11 +0100 Subject: [PATCH] cloud-setup: let dispatcher script run tool only if service is enabled We don't want that when the user installs the package, that the dispatcher script automatically executes the tool. Instead, the user should use `systemctl enable/disable` to control whether the service is active (of via the timer). Hence, let the dispatcher script check whether the service is enabled. That leads to a different problem, that we need to make it possible for "nm-cloud-setup.service" to be enabled in the first place. As such, add a [Install] section and let it be wanted by NetworkManager.service. The problem with this is that now the tool will run very early, just after NetworkManager started. At that point, it might not yet have setup networking. But that should be acceptable, after all, the tool either fails to fetch meta data that early, or it succeeds. Very likely, it will by aborted by dispatcher's restart command. (cherry picked from commit 953e01336a1c062ee988d3dfe4650dd7c4ba2778) --- clients/cloud-setup/90-nm-cloud-setup.sh | 4 +++- clients/cloud-setup/nm-cloud-setup.service.in | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clients/cloud-setup/90-nm-cloud-setup.sh b/clients/cloud-setup/90-nm-cloud-setup.sh index 9fb2a31da6..817e255581 100755 --- a/clients/cloud-setup/90-nm-cloud-setup.sh +++ b/clients/cloud-setup/90-nm-cloud-setup.sh @@ -2,6 +2,8 @@ case "$2" in up|dhcp4-change) - exec systemctl --no-block restart nm-cloud-setup.service + if systemctl -q is-enabled nm-cloud-setup.service ; then + exec systemctl --no-block restart nm-cloud-setup.service + fi ;; esac diff --git a/clients/cloud-setup/nm-cloud-setup.service.in b/clients/cloud-setup/nm-cloud-setup.service.in index d81abea2af..6a6485b8cf 100644 --- a/clients/cloud-setup/nm-cloud-setup.service.in +++ b/clients/cloud-setup/nm-cloud-setup.service.in @@ -1,5 +1,6 @@ [Unit] Description=Automatically configure NetworkManager in cloud +After=NetworkManager.service [Service] Type=oneshot @@ -25,3 +26,6 @@ RestrictNamespaces=yes RestrictRealtime=yes RestrictSUIDSGID=yes SystemCallFilter=@system-service + +[Install] +WantedBy=NetworkManager.service