1#!/usr/bin/env bash 2# SPDX-License-Identifier: LGPL-2.1-or-later 3set -eux 4 5systemd-analyze log-level debug 6 7systemd-run --unit=simple1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple1' true 8test -f /run/simple1 9 10systemd-run --unit=simple2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple -p ExecStopPost='/bin/touch /run/simple2' false \ 11 && { echo 'unexpected success'; exit 1; } 12test -f /run/simple2 13 14systemd-run --unit=exec1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec -p ExecStopPost='/bin/touch /run/exec1' sleep 1 15test -f /run/exec1 16 17systemd-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' \ 18 && { echo 'unexpected success'; exit 1; } 19test -f /run/exec2 20 21cat >/tmp/forking1.sh <<EOF 22#!/usr/bin/env bash 23 24set -eux 25 26sleep 4 & 27MAINPID=\$! 28disown 29 30systemd-notify MAINPID=\$MAINPID 31EOF 32chmod +x /tmp/forking1.sh 33 34systemd-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 35test -f /run/forking1 36 37cat >/tmp/forking2.sh <<EOF 38#!/usr/bin/env bash 39 40set -eux 41 42( sleep 4; exit 1 ) & 43MAINPID=\$! 44disown 45 46systemd-notify MAINPID=\$MAINPID 47EOF 48chmod +x /tmp/forking2.sh 49 50systemd-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 \ 51 && { echo 'unexpected success'; exit 1; } 52test -f /run/forking2 53 54systemd-run --unit=oneshot1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=oneshot -p ExecStopPost='/bin/touch /run/oneshot1' true 55test -f /run/oneshot1 56 57systemd-run --unit=oneshot2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=oneshot -p ExecStopPost='/bin/touch /run/oneshot2' false \ 58 && { echo 'unexpected success'; exit 1; } 59test -f /run/oneshot2 60 61systemd-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' \ 62 busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus RequestName su systemd.test.ExecStopPost 4 \ 63 || : 64test -f /run/dbus1 65 66systemd-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 67test -f /run/dbus2 68 69# https://github.com/systemd/systemd/issues/19920 70systemd-run --unit=dbus3.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=dbus -p ExecStopPost='/bin/touch /run/dbus3' true \ 71 && { echo 'unexpected success'; exit 1; } 72 73cat >/tmp/notify1.sh <<EOF 74#!/usr/bin/env bash 75 76set -eux 77 78systemd-notify --ready 79EOF 80chmod +x /tmp/notify1.sh 81 82systemd-run --unit=notify1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=notify -p ExecStopPost='/bin/touch /run/notify1' /tmp/notify1.sh 83test -f /run/notify1 84 85systemd-run --unit=notify2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=notify -p ExecStopPost='/bin/touch /run/notify2' true \ 86 && { echo 'unexpected success'; exit 1; } 87test -f /run/notify2 88 89systemd-run --unit=idle1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=idle -p ExecStopPost='/bin/touch /run/idle1' true 90test -f /run/idle1 91 92systemd-run --unit=idle2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=idle -p ExecStopPost='/bin/touch /run/idle2' false \ 93 && { echo 'unexpected success'; exit 1; } 94test -f /run/idle2 95 96systemd-analyze log-level info 97 98echo OK >/testok 99 100exit 0 101