]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/units/testsuite-82.sh
Revert "core: add IgnoreOnSoftReboot= unit option"
[thirdparty/systemd.git] / test / units / testsuite-82.sh
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -ex
4 set -o pipefail
5
6 systemd-analyze log-level debug
7
8 export SYSTEMD_LOG_LEVEL=debug
9
10 if [ -f /run/testsuite82.touch3 ]; then
11 echo "This is the fourth boot!"
12 systemd-notify --status="Fourth Boot"
13
14 rm /run/testsuite82.touch3
15 mount
16 rmdir /original-root /run/nextroot
17
18 # Check that the fdstore entry still exists
19 test "$LISTEN_FDS" -eq 3
20 read -r x <&5
21 test "$x" = "oinkoink"
22
23 # Check that the surviving service is still around
24 test "$(systemctl show -P ActiveState testsuite-82-survive.service)" = "active"
25 test "$(systemctl show -P ActiveState testsuite-82-nosurvive.service)" != "active"
26
27 # Take out the big guns now, and kill the service via SIGKILL (SIGTERM is blocked after all, see below)
28 systemctl --signal=KILL kill testsuite-82-survive.service
29 systemctl stop testsuite-82-survive.service
30
31 # All succeeded, exit cleanly now
32
33 elif [ -f /run/testsuite82.touch2 ]; then
34 echo "This is the third boot!"
35 systemd-notify --status="Third Boot"
36
37 rm /run/testsuite82.touch2
38
39 # Check that the fdstore entry still exists
40 test "$LISTEN_FDS" -eq 2
41 read -r x <&4
42 test "$x" = "miaumiau"
43
44 # Upload another entry
45 T="/dev/shm/fdstore.$RANDOM"
46 echo "oinkoink" >"$T"
47 systemd-notify --fd=3 --pid=parent 3<"$T"
48 rm "$T"
49
50 # Check that the surviving service is still around
51 test "$(systemctl show -P ActiveState testsuite-82-survive.service)" = "active"
52 test "$(systemctl show -P ActiveState testsuite-82-nosurvive.service)" != "active"
53
54 # Test that we really are in the new overlayfs root fs
55 read -r x </lower
56 test "$x" = "miep"
57 cmp /etc/os-release /run/systemd/propagate/os-release
58 grep -q MARKER=1 /etc/os-release
59
60 # Switch back to the original root, away from the overlayfs
61 mount --bind /original-root /run/nextroot
62 mount
63
64 # Now issue the soft reboot. We should be right back soon.
65 touch /run/testsuite82.touch3
66 systemctl --no-block soft-reboot
67
68 # Now block until the soft-boot killing spree kills us
69 exec sleep infinity
70
71 elif [ -f /run/testsuite82.touch ]; then
72 echo "This is the second boot!"
73 systemd-notify --status="Second Boot"
74
75 # Clean up what we created earlier
76 rm /run/testsuite82.touch
77
78 # Check that the fdstore entry still exists
79 test "$LISTEN_FDS" -eq 1
80 read -r x <&3
81 test "$x" = "wuffwuff"
82
83 # Upload another entry
84 T="/dev/shm/fdstore.$RANDOM"
85 echo "miaumiau" >"$T"
86 systemd-notify --fd=3 --pid=parent 3<"$T"
87 rm "$T"
88
89 # Check that the surviving service is still around
90 test "$(systemctl show -P ActiveState testsuite-82-survive.service)" = "active"
91 test "$(systemctl show -P ActiveState testsuite-82-nosurvive.service)" != "active"
92
93 # This time we test the /run/nextroot/ root switching logic. (We synthesize a new rootfs from the old via overlayfs)
94 mkdir -p /run/nextroot /tmp/nextroot-lower /original-root
95 mount -t tmpfs tmpfs /tmp/nextroot-lower
96 echo miep >/tmp/nextroot-lower/lower
97
98 # Copy os-release away, so that we can manipulate it and check that it is updated in the propagate
99 # directory across soft reboots.
100 mkdir -p /tmp/nextroot-lower/usr/lib
101 cp /etc/os-release /tmp/nextroot-lower/usr/lib/os-release
102 echo MARKER=1 >>/tmp/nextroot-lower/usr/lib/os-release
103 cmp /etc/os-release /run/systemd/propagate/os-release
104 (! grep -q MARKER=1 /etc/os-release)
105
106 mount -t overlay nextroot /run/nextroot -o lowerdir=/tmp/nextroot-lower:/,ro
107
108 # Bind our current root into the target so that we later can return to it
109 mount --bind / /run/nextroot/original-root
110
111 # Now issue the soft reboot. We should be right back soon.
112 touch /run/testsuite82.touch2
113 systemctl --no-block soft-reboot
114
115 # Now block until the soft-boot killing spree kills us
116 exec sleep infinity
117 else
118 # This is the first boot
119 systemd-notify --status="First Boot"
120
121 # Let's upload an fd to the fdstore, so that we can verify fdstore passing works correctly
122 T="/dev/shm/fdstore.$RANDOM"
123 echo "wuffwuff" >"$T"
124 systemd-notify --fd=3 --pid=parent 3<"$T"
125 rm "$T"
126
127 # Create a script that can survive the soft reboot by ignoring SIGTERM (we
128 # do this instead of the argv[0][0] = '@' thing because that's so hard to
129 # do from a shell
130 T="/dev/shm/survive-$RANDOM.sh"
131 cat >$T <<EOF
132 #!/bin/bash
133 trap "" TERM
134 systemd-notify --ready
135 rm "$T"
136 exec sleep infinity
137 EOF
138 chmod +x "$T"
139 # This sets DefaultDependencies=no so that it remains running until the
140 # very end, and IgnoreOnIsolate=yes so that it isn't stopped via the
141 # "testsuite.target" isolation we do on next boot
142 systemd-run -p Type=notify -p DefaultDependencies=no -p IgnoreOnIsolate=yes --unit=testsuite-82-survive.service "$T"
143 systemd-run -p Type=exec -p DefaultDependencies=no -p IgnoreOnIsolate=yes --unit=testsuite-82-nosurvive.service sleep infinity
144
145 # Now issue the soft reboot. We should be right back soon.
146 touch /run/testsuite82.touch
147 systemctl --no-block soft-reboot
148
149 # Now block until the soft-boot killing spree kills us
150 exec sleep infinity
151 fi
152
153 systemd-analyze log-level info
154
155 touch /testok
156 systemctl --no-block poweroff