]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-56.sh
Merge pull request #21517 from yuwata/network-long-hw-addr
[thirdparty/systemd.git] / test / units / testsuite-56.sh
1 #!/usr/bin/env bash
2 set -eux
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 systemd-notify --ready
19
20 # Run the stop/kill command
21 \$1 &
22
23 # process tree: systemd -> bash -> sleep
24 sleep infinity
25 EOF
26 chmod +x /tmp/test56-exit-cgroup.sh
27
28 # service should be stopped cleanly
29 systemd-run --wait --unit=one -p Type=notify -p ExitType=cgroup \
30 /tmp/test56-exit-cgroup.sh 'systemctl stop one'
31
32 # same thing with a truthy exec condition
33 systemd-run --wait --unit=two -p Type=notify -p ExitType=cgroup \
34 -p ExecCondition=true \
35 /tmp/test56-exit-cgroup.sh 'systemctl stop two'
36
37 # false exec condition: systemd-run should exit immediately with status code: 1
38 systemd-run --wait --unit=three -p Type=notify -p ExitType=cgroup \
39 -p ExecCondition=false \
40 /tmp/test56-exit-cgroup.sh \
41 && { echo 'unexpected success'; exit 1; }
42
43 # service should exit uncleanly (main process exits with SIGKILL)
44 systemd-run --wait --unit=four -p Type=notify -p ExitType=cgroup \
45 /tmp/test56-exit-cgroup.sh 'systemctl kill --signal 9 four' \
46 && { echo 'unexpected success'; exit 1; }
47
48
49 # Multiple level process tree, parent process exits quickly
50 cat >/tmp/test56-exit-cgroup-parentless.sh <<EOF
51 #!/usr/bin/env bash
52 set -eux
53
54 # process tree: systemd -> sleep
55 sleep infinity &
56
57 # process tree: systemd -> bash -> sleep
58 ((sleep infinity); true) &
59
60 systemd-notify --ready
61
62 # Run the stop/kill command after this bash process exits
63 (sleep 1; \$1) &
64 EOF
65 chmod +x /tmp/test56-exit-cgroup-parentless.sh
66
67 # service should be stopped cleanly
68 systemd-run --wait --unit=five -p Type=notify -p ExitType=cgroup \
69 /tmp/test56-exit-cgroup-parentless.sh 'systemctl stop five'
70
71 # service should still exit cleanly despite SIGKILL (the main process already exited cleanly)
72 systemd-run --wait --unit=six -p Type=notify -p ExitType=cgroup \
73 /tmp/test56-exit-cgroup-parentless.sh 'systemctl kill --signal 9 six'
74
75
76 systemd-analyze log-level info
77
78 echo OK >/testok
79
80 exit 0