File: TEST-23-UNIT-FILE.ExecStopPost.sh

package info (click to toggle)
systemd 259.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 113,388 kB
  • sloc: ansic: 727,211; xml: 121,125; python: 36,732; sh: 34,990; cpp: 946; makefile: 278; awk: 102; lisp: 13; sed: 1
file content (101 lines) | stat: -rwxr-xr-x 3,416 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eux

# Test that ExecStopPost= is always run

systemd-run --unit=simple1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple \
    -p ExecStopPost='touch /run/simple1' true
test -f /run/simple1

(! systemd-run --unit=simple2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=simple \
    -p ExecStopPost='touch /run/simple2' false)
test -f /run/simple2

systemd-run --unit=exec1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec \
    -p ExecStopPost='touch /run/exec1' sleep 1
test -f /run/exec1

(! systemd-run --unit=exec2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=exec \
   -p ExecStopPost='touch /run/exec2' bash -c 'sleep 1; false')
test -f /run/exec2

cat >/tmp/forking1.sh <<EOF
#!/usr/bin/env bash

set -eux

sleep 4 &
MAINPID=\$!
disown

systemd-notify MAINPID=\$MAINPID
EOF
chmod +x /tmp/forking1.sh

systemd-run --unit=forking1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=forking -p NotifyAccess=exec \
        -p ExecStopPost='touch /run/forking1' /tmp/forking1.sh
test -f /run/forking1

cat >/tmp/forking2.sh <<EOF
#!/usr/bin/env bash

set -eux

(sleep 4; exit 1) &
MAINPID=\$!
disown

systemd-notify MAINPID=\$MAINPID
EOF
chmod +x /tmp/forking2.sh

(! systemd-run --unit=forking2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=forking -p NotifyAccess=exec \
    -p ExecStopPost='touch /run/forking2' /tmp/forking2.sh)
test -f /run/forking2

systemd-run --unit=oneshot1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=oneshot \
    -p ExecStopPost='touch /run/oneshot1' true
test -f /run/oneshot1

(! systemd-run --unit=oneshot2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=oneshot \
    -p ExecStopPost='touch /run/oneshot2' false)
test -f /run/oneshot2

systemd-run --unit=dbus1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=dbus -p BusName=systemd.test.ExecStopPost \
    -p ExecStopPost='touch /run/dbus1' \
    busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus RequestName su systemd.test.ExecStopPost 4 || :
test -f /run/dbus1

systemd-run --unit=dbus2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=dbus -p BusName=systemd.test.ExecStopPost \
    -p ExecStopPost='touch /run/dbus2' true
test -f /run/dbus2

# https://github.com/systemd/systemd/issues/19920
(! systemd-run --unit=dbus3.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=dbus \
    -p ExecStopPost='touch /run/dbus3' true)

cat >/tmp/notify1.sh <<EOF
#!/usr/bin/env bash

set -eux

systemd-notify --ready
EOF
chmod +x /tmp/notify1.sh

systemd-run --unit=notify1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=notify \
    -p ExecStopPost='touch /run/notify1' /tmp/notify1.sh
test -f /run/notify1

(! systemd-run --unit=notify2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=notify \
    -p ExecStopPost='touch /run/notify2' true)
test -f /run/notify2

systemd-run --unit=idle1.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=idle \
    -p ExecStopPost='touch /run/idle1' true
test -f /run/idle1

(! systemd-run --unit=idle2.service --wait -p StandardOutput=tty -p StandardError=tty -p Type=idle \
    -p ExecStopPost='touch /run/idle2' false)
test -f /run/idle2