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 <<EOF
[Unit]
check_ok test15-b ExecCondition "/bin/echo test15-b"
rm -rf /usr/lib/systemd/system/service.d
- clear_services test15-a test15-b test15-c test15-c1
+ clear_units test15-{a,b,c,c1}.service
}
test_linked_units () {
# Make sure it is completely ignored.
rm /test15-a@.scope
- clear_services test15-a test15-b
+ clear_units test15-{a,b}.service
}
test_template_alias() {
check_ko test15-b@other Names test15-a@other.service
check_ok test15-b@other Names test15-b@other.service
- clear_services test15-a@ test15-b@
+ clear_units test15-{a,b}@.service
}
test_hierarchical_dropins () {
rm -rf /usr/lib/systemd/system/$dropin
done
- clear_services a-b-c
+ clear_units a-b-c.service
}
test_template_dropins () {
check_ok bar-alias@3 Requires yup-template-requires.device
check_ok bar-alias@3 Requires yup-3-requires.device
- clear_services foo {bar,yup,bar-alias}@{,1,2,3}
+ clear_units foo.service {bar,yup,bar-alias}@{,1,2,3}.service
}
test_alias_dropins () {
systemctl --quiet is-active test15-b
systemctl stop test15-a test15-b
rm /etc/systemd/system/test15-b1.service
- clear_services test15-a test15-b
+ clear_units test15-{a,b}.service
# Check that dependencies don't vary.
echo "*** test 2"
systemctl stop test15-a test15-x test15-y
rm /etc/systemd/system/test15-a1.service
- clear_services test15-a test15-x test15-y
+ clear_units test15-{a,x,y}.service
}
test_masked_dropins () {
ln -sf /dev/null /etc/systemd/system/test15-a.service.requires/test15-b.service
check_ok test15-a Requires test15-b
- clear_services test15-a test15-b
+ clear_units test15-{a,b}.service
}
test_invalid_dropins () {
# Assertion failed on earlier versions, command exits unsuccessfully on later versions
systemctl cat a@.service || true
systemctl stop a
- clear_services a
+ clear_units a.service
return 0
}
ln -s /tmp/testsuite-15-test15-a-dropin-directory-regular /usr/lib/systemd/system/test15-a.service.d
check_ok test15-a Description hogehoge
- clear_services test15-a
+ clear_units test15-a.service
}
test_basic_dropins