]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
TEST-07-PID1: add test cases for mask/unmask unit
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 3 Sep 2025 18:21:45 +0000 (03:21 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 7 Oct 2025 09:48:58 +0000 (11:48 +0200)
For issue #38802.

(cherry picked from commit 023de387821dd142fbc86d0882a904b87cb01b6a)

test/units/TEST-07-PID1.mask.sh [new file with mode: 0755]

diff --git a/test/units/TEST-07-PID1.mask.sh b/test/units/TEST-07-PID1.mask.sh
new file mode 100755 (executable)
index 0000000..33c74f0
--- /dev/null
@@ -0,0 +1,90 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+set -o pipefail
+
+at_exit() {
+    set +e
+
+    systemctl stop mask-test.service
+    rm -rf /run/systemd/system/mask-test.service*
+    systemctl daemon-reload
+
+    rm -f /tmp/should-not-exist-by-*
+}
+
+trap at_exit EXIT
+
+rm -f /tmp/should-not-exist-by-*
+
+mkdir -p /run/systemd/system/mask-test.service.d
+
+cat >/run/systemd/system/mask-test.service <<EOF
+[Service]
+Type=exec
+ExecStart=sleep infinity
+ExecStop=touch /tmp/should-not-exist-by-main
+EOF
+
+# Check if ExecStop= and friends in a masked unit are not executed even defined
+# in drop-in. See issue #38802.
+cat >/run/systemd/system/mask-test.service.d/10-stop.conf <<EOF
+[Service]
+ExecStop=touch /tmp/should-not-exist-by-dropin
+EOF
+
+systemctl daemon-reload
+[[ "$(systemctl is-enabled mask-test.service || :)" == static ]]
+
+systemctl start mask-test.service
+[[ "$(systemctl is-active mask-test.service || :)" == active ]]
+
+# When not masked, of course ExecStop= are executed.
+systemctl stop mask-test.service
+[[ "$(systemctl is-active mask-test.service || :)" == inactive ]]
+[[ -f /tmp/should-not-exist-by-main ]]
+[[ -f /tmp/should-not-exist-by-dropin ]]
+rm -f /tmp/should-not-exist-by-*
+
+systemctl start mask-test.service
+[[ "$(systemctl is-active mask-test.service || :)" == active ]]
+
+# Check if mask --now works and ExecStop= are not executed.
+systemctl mask --now mask-test.service
+[[ "$(systemctl is-enabled mask-test.service || :)" == masked ]]
+[[ "$(systemctl is-active mask-test.service || :)" == inactive ]]
+[[ ! -f /tmp/should-not-exist-by-main ]]
+[[ ! -f /tmp/should-not-exist-by-dropin ]]
+
+systemctl unmask mask-test.service
+[[ "$(systemctl is-enabled mask-test.service || :)" == static ]]
+
+systemctl start mask-test.service
+[[ "$(systemctl is-active mask-test.service || :)" == active ]]
+
+systemctl mask mask-test.service
+[[ "$(systemctl is-enabled mask-test.service || :)" == masked ]]
+[[ "$(systemctl is-active mask-test.service || :)" == active ]]
+
+# Check if mask --now for already masked unit stops the service.
+systemctl mask --now mask-test.service
+[[ "$(systemctl is-enabled mask-test.service || :)" == masked ]]
+[[ "$(systemctl is-active mask-test.service || :)" == inactive ]]
+[[ ! -f /tmp/should-not-exist-by-main ]]
+[[ ! -f /tmp/should-not-exist-by-dropin ]]
+
+systemctl unmask mask-test.service
+[[ "$(systemctl is-enabled mask-test.service || :)" == static ]]
+
+systemctl start mask-test.service
+[[ "$(systemctl is-active mask-test.service || :)" == active ]]
+
+systemctl mask mask-test.service
+[[ "$(systemctl is-enabled mask-test.service || :)" == masked ]]
+[[ "$(systemctl is-active mask-test.service || :)" == active ]]
+
+# Check if already masked unit can be stopped.
+systemctl stop mask-test.service
+[[ "$(systemctl is-active mask-test.service || :)" == inactive ]]
+[[ ! -f /tmp/should-not-exist-by-main ]]
+[[ ! -f /tmp/should-not-exist-by-dropin ]]