From 8a85dd4af8e4948299b4c84df65c789999024d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 16 Oct 2022 12:42:35 +0200 Subject: [PATCH] TEST-15: allow helper functions to accept other unit types clear_services() is renamed to clear_units() and now takes a full unit name including the suffix as an argument. _clear_service() is renamed to clear_unit() and changed likewise. create_service() didn't have the same underscore prefix, and I don't think it's useful or needed for a local function, so it is removed. No functional change. (cherry picked from commit 5731e1378ad6256e34f3da33ee993343f025c075) Related: #2156620 --- test/TEST-15-DROPIN/test-dropin.sh | 44 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/test/TEST-15-DROPIN/test-dropin.sh b/test/TEST-15-DROPIN/test-dropin.sh index c2c96d9797..bcd351360d 100755 --- a/test/TEST-15-DROPIN/test-dropin.sh +++ b/test/TEST-15-DROPIN/test-dropin.sh @@ -3,30 +3,32 @@ set -e set -x -_clear_service () { - local SERVICE_NAME="${1:?}" - systemctl stop "$SERVICE_NAME.service" 2>/dev/null || : - rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service - rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.d - rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.{wants,requires} - if [[ $SERVICE_NAME == *@ ]]; then - systemctl stop "$SERVICE_NAME"*.service 2>/dev/null || : - rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service - rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.d - rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.{wants,requires} +clear_unit () { + local UNIT_NAME="${1:?}" + systemctl stop "$UNIT_NAME" 2>/dev/null || : + rm -f /{etc,run,usr/lib}/systemd/system/"$UNIT_NAME" + rm -fr /{etc,run,usr/lib}/systemd/system/"$UNIT_NAME".d + rm -fr /{etc,run,usr/lib}/systemd/system/"$UNIT_NAME".{wants,requires} + if [[ $UNIT_NAME == *@ ]]; then + local base="${UNIT_NAME%@*}" + local suffix="${UNIT_NAME##*.}" + systemctl stop "$base@"*."$suffix" 2>/dev/null || : + rm -f /{etc,run,usr/lib}/systemd/system/"$base@"*."$suffix" + rm -fr /{etc,run,usr/lib}/systemd/system/"$base@"*."$suffix".d + rm -fr /{etc,run,usr/lib}/systemd/system/"$base@"*."$suffix".{wants,requires} fi } -clear_services () { +clear_units () { for u in "$@"; do - _clear_service "$u" + clear_unit "$u" done systemctl daemon-reload } create_service () { local SERVICE_NAME="${1:?}" - clear_services "$SERVICE_NAME" + clear_units "${SERVICE_NAME}".service cat >/etc/systemd/system/"$SERVICE_NAME".service <