2 # SPDX-License-Identifier: LGPL-2.1-or-later
6 systemd-analyze log-level debug
8 export SYSTEMD_LOG_LEVEL
=debug
10 if [ -f /run
/testsuite82.touch3
]; then
11 echo "This is the fourth boot!"
12 systemd-notify
--status="Fourth Boot"
14 rm /run
/testsuite82.touch3
16 rmdir /original-root
/run
/nextroot
18 # Check that the fdstore entry still exists
19 test "$LISTEN_FDS" -eq 3
21 test "$x" = "oinkoink"
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"
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
31 # All succeeded, exit cleanly now
33 elif [ -f /run
/testsuite82.touch2
]; then
34 echo "This is the third boot!"
35 systemd-notify
--status="Third Boot"
37 rm /run
/testsuite82.touch2
39 # Check that the fdstore entry still exists
40 test "$LISTEN_FDS" -eq 2
42 test "$x" = "miaumiau"
44 # Upload another entry
45 T
="/dev/shm/fdstore.$RANDOM"
47 systemd-notify
--fd=3 --pid=parent
3<"$T"
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"
54 # Test that we really are in the new overlayfs root fs
57 cmp /etc
/os-release
/run
/systemd
/propagate
/os-release
58 grep -q MARKER
=1 /etc
/os-release
60 # Switch back to the original root, away from the overlayfs
61 mount
--bind /original-root
/run
/nextroot
64 # Now issue the soft reboot. We should be right back soon.
65 touch /run
/testsuite82.touch3
66 systemctl
--no-block soft-reboot
68 # Now block until the soft-boot killing spree kills us
71 elif [ -f /run
/testsuite82.
touch ]; then
72 echo "This is the second boot!"
73 systemd-notify
--status="Second Boot"
75 # Clean up what we created earlier
76 rm /run
/testsuite82.
touch
78 # Check that the fdstore entry still exists
79 test "$LISTEN_FDS" -eq 1
81 test "$x" = "wuffwuff"
83 # Upload another entry
84 T
="/dev/shm/fdstore.$RANDOM"
86 systemd-notify
--fd=3 --pid=parent
3<"$T"
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"
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
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
)
106 mount
-t overlay nextroot
/run
/nextroot
-o lowerdir
=/tmp
/nextroot-lower
:/,ro
108 # Bind our current root into the target so that we later can return to it
109 mount
--bind / /run
/nextroot
/original-root
111 # Now issue the soft reboot. We should be right back soon.
112 touch /run
/testsuite82.touch2
113 systemctl
--no-block soft-reboot
115 # Now block until the soft-boot killing spree kills us
118 # This is the first boot
119 systemd-notify
--status="First Boot"
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"
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
130 T
="/dev/shm/survive-$RANDOM.sh"
134 systemd-notify --ready
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
145 # Now issue the soft reboot. We should be right back soon.
146 touch /run
/testsuite82.
touch
147 systemctl
--no-block soft-reboot
149 # Now block until the soft-boot killing spree kills us
153 systemd-analyze log-level info
156 systemctl
--no-block poweroff