diff --git a/test/units/testsuite-15.sh b/test/units/testsuite-15.sh index f847adac744..5f7387fb8b2 100755 --- a/test/units/testsuite-15.sh +++ b/test/units/testsuite-15.sh @@ -3,30 +3,32 @@ set -eux set -o pipefail -_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 <