]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-56.sh
Merge pull request #18886 from anitazha/shutdownconsole
[thirdparty/systemd.git] / test / units / testsuite-56.sh
1 #!/usr/bin/env bash
2 set -ex
3
4 systemd-analyze log-level debug
5
6 # Multiple level process tree, parent process stays up
7 cat >/tmp/test56-exit-cgroup.sh <<EOF
8 #!/usr/bin/env bash
9 set -eux
10
11 # process tree: systemd -> sleep
12 sleep infinity &
13 disown
14
15 # process tree: systemd -> bash -> bash -> sleep
16 ((sleep infinity); true) &
17
18 # process tree: systemd -> bash -> sleep
19 sleep infinity
20 EOF
21 chmod +x /tmp/test56-exit-cgroup.sh
22
23 # service should be stopped cleanly
24 (sleep 1; systemctl stop one) &
25 systemd-run --wait --unit=one -p ExitType=cgroup /tmp/test56-exit-cgroup.sh
26
27 # same thing with a truthy exec condition
28 (sleep 1; systemctl stop two) &
29 systemd-run --wait --unit=two -p ExitType=cgroup -p ExecCondition=true /tmp/test56-exit-cgroup.sh
30
31 # false exec condition: systemd-run should exit immediately with status code: 1
32 ! systemd-run --wait --unit=three -p ExitType=cgroup -p ExecCondition=false /tmp/test56-exit-cgroup.sh
33
34 # service should exit uncleanly
35 (sleep 1; systemctl kill --signal 9 four) &
36 ! systemd-run --wait --unit=four -p ExitType=cgroup /tmp/test56-exit-cgroup.sh
37
38
39 # Multiple level process tree, parent process exits quickly
40 cat >/tmp/test56-exit-cgroup-parentless.sh <<EOF
41 #!/usr/bin/env bash
42 set -eux
43
44 # process tree: systemd -> sleep
45 sleep infinity &
46
47 # process tree: systemd -> bash -> sleep
48 ((sleep infinity); true) &
49 EOF
50 chmod +x /tmp/test56-exit-cgroup-parentless.sh
51
52 # service should be stopped cleanly
53 (sleep 1; systemctl stop five) &
54 systemd-run --wait --unit=five -p ExitType=cgroup /tmp/test56-exit-cgroup-parentless.sh
55
56 # service should exit uncleanly
57 (sleep 1; systemctl kill --signal 9 six) &
58 ! systemd-run --wait --unit=six -p ExitType=cgroup /tmp/test56-exit-cgroup-parentless.sh
59
60
61 # Multiple level process tree, parent process exits uncleanly but last process exits cleanly
62 cat >/tmp/test56-exit-cgroup-clean.sh <<EOF
63 #!/usr/bin/env bash
64 set -eux
65
66 # process tree: systemd -> bash -> sleep
67 (sleep 1; true) &
68
69 exit 255
70 EOF
71 chmod +x /tmp/test56-exit-cgroup-clean.sh
72
73 # service should exit cleanly and be garbage-collected
74 systemd-run --wait --unit=seven -p ExitType=cgroup /tmp/test56-exit-cgroup-clean.sh
75
76
77 # Multiple level process tree, parent process exits cleanly but last process exits uncleanly
78 cat >/tmp/test56-exit-cgroup-unclean.sh <<EOF
79 #!/usr/bin/env bash
80 set -eux
81
82 # process tree: systemd -> bash -> sleep
83 (sleep 1; exit 255) &
84 EOF
85 chmod +x /tmp/test56-exit-cgroup-unclean.sh
86
87 # service should exit uncleanly after 1 second
88 ! systemd-run --wait --unit=eight -p ExitType=cgroup /tmp/test56-exit-cgroup-unclean.sh
89
90 systemd-analyze log-level info
91
92 echo OK > /testok
93
94 exit 0