2020-03-04 12:35:06 +03:00
#!/usr/bin/env bash
2021-10-17 19:13:06 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2021-04-09 20:39:41 +03:00
set -eux
2019-10-03 20:05:06 +03:00
2023-05-08 23:38:34 +03:00
# Test that ExecStopPost= is always run
2019-10-03 20:05:06 +03:00
systemd-analyze log-level debug
2023-04-05 16:50:42 +03:00
systemd-run --unit= simple1.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = simple \
-p ExecStopPost = '/bin/touch /run/simple1' true
2019-10-03 20:05:06 +03:00
test -f /run/simple1
2023-04-05 16:50:42 +03:00
( ! systemd-run --unit= simple2.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = simple \
-p ExecStopPost = '/bin/touch /run/simple2' false )
2019-10-03 20:05:06 +03:00
test -f /run/simple2
2023-04-05 16:50:42 +03:00
systemd-run --unit= exec1.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = exec \
-p ExecStopPost = '/bin/touch /run/exec1' sleep 1
2019-10-03 20:05:06 +03:00
test -f /run/exec1
2023-04-05 16:50:42 +03:00
( ! systemd-run --unit= exec2.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = exec \
-p ExecStopPost = '/bin/touch /run/exec2' sh -c 'sleep 1; false' )
2019-10-03 20:05:06 +03:00
test -f /run/exec2
2021-04-08 01:09:55 +03:00
cat >/tmp/forking1.sh <<EOF
2020-03-04 12:35:06 +03:00
#!/usr/bin/env bash
2019-10-03 20:05:06 +03:00
set -eux
sleep 4 &
MAINPID = \$ !
disown
systemd-notify MAINPID = \$ MAINPID
EOF
chmod +x /tmp/forking1.sh
2023-04-05 16:50:42 +03:00
systemd-run --unit= forking1.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = forking -p NotifyAccess = exec \
-p ExecStopPost = '/bin/touch /run/forking1' /tmp/forking1.sh
2019-10-03 20:05:06 +03:00
test -f /run/forking1
2021-04-08 01:09:55 +03:00
cat >/tmp/forking2.sh <<EOF
2020-03-04 12:35:06 +03:00
#!/usr/bin/env bash
2019-10-03 20:05:06 +03:00
set -eux
2023-04-05 16:50:42 +03:00
( sleep 4; exit 1) &
2019-10-03 20:05:06 +03:00
MAINPID = \$ !
disown
systemd-notify MAINPID = \$ MAINPID
EOF
chmod +x /tmp/forking2.sh
2023-04-05 16:50:42 +03:00
( ! systemd-run --unit= forking2.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = forking -p NotifyAccess = exec \
-p ExecStopPost = '/bin/touch /run/forking2' /tmp/forking2.sh)
2019-10-03 20:05:06 +03:00
test -f /run/forking2
2023-04-05 16:50:42 +03:00
systemd-run --unit= oneshot1.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = oneshot \
-p ExecStopPost = '/bin/touch /run/oneshot1' true
2019-10-03 20:05:06 +03:00
test -f /run/oneshot1
2023-04-05 16:50:42 +03:00
( ! systemd-run --unit= oneshot2.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = oneshot \
-p ExecStopPost = '/bin/touch /run/oneshot2' false )
2019-10-03 20:05:06 +03:00
test -f /run/oneshot2
2023-04-05 16:50:42 +03:00
systemd-run --unit= dbus1.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = dbus -p BusName = systemd.test.ExecStopPost \
-p ExecStopPost = '/bin/touch /run/dbus1' \
busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus RequestName su systemd.test.ExecStopPost 4 || :
2019-10-03 20:05:06 +03:00
test -f /run/dbus1
2023-04-05 16:50:42 +03:00
systemd-run --unit= dbus2.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = dbus -p BusName = systemd.test.ExecStopPost \
-p ExecStopPost = '/bin/touch /run/dbus2' true
2019-10-03 20:05:06 +03:00
test -f /run/dbus2
2021-06-14 21:05:48 +03:00
# https://github.com/systemd/systemd/issues/19920
2023-04-05 16:50:42 +03:00
( ! systemd-run --unit= dbus3.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = dbus \
-p ExecStopPost = '/bin/touch /run/dbus3' true )
2021-06-14 21:05:48 +03:00
2021-04-08 01:09:55 +03:00
cat >/tmp/notify1.sh <<EOF
2020-03-04 12:35:06 +03:00
#!/usr/bin/env bash
2019-10-03 20:05:06 +03:00
set -eux
systemd-notify --ready
EOF
chmod +x /tmp/notify1.sh
2023-04-05 16:50:42 +03:00
systemd-run --unit= notify1.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = notify \
-p ExecStopPost = '/bin/touch /run/notify1' /tmp/notify1.sh
2019-10-03 20:05:06 +03:00
test -f /run/notify1
2023-04-05 16:50:42 +03:00
( ! systemd-run --unit= notify2.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = notify \
-p ExecStopPost = '/bin/touch /run/notify2' true )
2019-10-03 20:05:06 +03:00
test -f /run/notify2
systemd-run --unit= idle1.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = idle -p ExecStopPost = '/bin/touch /run/idle1' true
test -f /run/idle1
2023-04-05 16:50:42 +03:00
( ! systemd-run --unit= idle2.service --wait -p StandardOutput = tty -p StandardError = tty -p Type = idle \
-p ExecStopPost = '/bin/touch /run/idle2' false )
2019-10-03 20:05:06 +03:00
test -f /run/idle2
systemd-analyze log-level info