#!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later set -eux set -o pipefail # shellcheck source=test/units/test-control.sh . "$(dirname "$0")"/test-control.sh clear_unit() { local unit_name="${1:?}" local base suffix 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 base="${unit_name%@*}" 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_units() { for u in "$@"; do clear_unit "$u" done systemctl daemon-reload } create_service() { local service_name="${1:?}" clear_units "${service_name}".service cat >/etc/systemd/system/"$service_name".service </run/systemd/system/service.d/override.conf <"/run/systemd/system/$dropin/override.conf" <"/run/systemd/system/$dropin/override.conf" </run/systemd/system/a-b-c.slice </etc/systemd/system/service.d/drop1.conf echo -e '[Service]\nStandardInputText=bbb' >/etc/systemd/system/a-.service.d/drop2.conf echo -e '[Service]\nStandardInputText=ccc' >/etc/systemd/system/a-b-.service.d/drop3.conf echo -e '[Service]\nStandardInputText=ddd' >/etc/systemd/system/a-b-c.service.d/drop4.conf # There's no fragment yet, so this fails systemctl cat a-b-c.service && exit 1 # xxx → eHh4Cg== systemd-run -u a-b-c.service -p StandardInputData=eHh4Cg== sleep infinity data=$(systemctl show -P StandardInputData a-b-c.service) # xxx\naaa\n\bbb\nccc\nddd\n → eHh4… test "$data" = "eHh4CmFhYQpiYmIKY2NjCmRkZAo=" # Do a reload and check again systemctl daemon-reload data=$(systemctl show -P StandardInputData a-b-c.service) test "$data" = "eHh4CmFhYQpiYmIKY2NjCmRkZAo=" clear_units a-b-c.service rm /etc/systemd/system/service.d/drop1.conf \ /etc/systemd/system/a-.service.d/drop2.conf \ /etc/systemd/system/a-b-.service.d/drop3.conf } testcase_transient_slice_dropins() { echo "Testing dropins for a transient slice..." echo "*** test transient slice drop-ins" # FIXME: implement reloading of individual units. # # The settings here are loaded twice. For most settings it doesn't matter, # but Documentation is not deduplicated, so we current get repeated entried # which is a bug. mkdir -p /etc/systemd/system/slice.d mkdir -p /etc/systemd/system/a-.slice.d mkdir -p /etc/systemd/system/a-b-.slice.d mkdir -p /etc/systemd/system/a-b-c.slice.d echo -e '[Unit]\nDocumentation=man:drop1' >/etc/systemd/system/slice.d/drop1.conf echo -e '[Unit]\nDocumentation=man:drop2' >/etc/systemd/system/a-.slice.d/drop2.conf echo -e '[Unit]\nDocumentation=man:drop3' >/etc/systemd/system/a-b-.slice.d/drop3.conf echo -e '[Unit]\nDocumentation=man:drop4' >/etc/systemd/system/a-b-c.slice.d/drop4.conf # Invoke daemon-reload to make sure that the call below doesn't fail systemctl daemon-reload # No fragment is required, so this works systemctl cat a-b-c.slice busctl call \ org.freedesktop.systemd1 \ /org/freedesktop/systemd1 \ org.freedesktop.systemd1.Manager \ StartTransientUnit 'ssa(sv)a(sa(sv))' \ 'a-b-c.slice' 'replace' \ 1 \ 'Documentation' as 1 'man:drop5' \ 0 data=$(systemctl show -P Documentation a-b-c.slice) test "$data" = "man:drop1 man:drop2 man:drop3 man:drop4 man:drop5 man:drop1 man:drop2 man:drop3 man:drop4" # Do a reload and check again systemctl daemon-reload data=$(systemctl show -P Documentation a-b-c.slice) test "$data" = "man:drop5 man:drop1 man:drop2 man:drop3 man:drop4" clear_units a-b-c.slice rm /etc/systemd/system/slice.d/drop1.conf \ /etc/systemd/system/a-.slice.d/drop2.conf \ /etc/systemd/system/a-b-.slice.d/drop3.conf } testcase_template_dropins() { echo "Testing template dropins..." create_services foo bar@ yup@ # Declare some deps to check if the body was loaded cat >>/etc/systemd/system/bar@.service <>/etc/systemd/system/yup@.service </usr/lib/systemd/system/test15-a.service.d/override.conf </usr/lib/systemd/system/test15-a.service.d/wants-b.conf </tmp/testsuite-15-test15-a-dropin-directory/override.conf <