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 no 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 # All succeeded, exit cleanly now
29 elif [ -f /run
/testsuite82.touch2
]; then
30 echo "This is the third boot!"
31 systemd-notify
--status="Third Boot"
33 rm /run
/testsuite82.touch2
35 # Check that the fdstore entry still exists
36 test "$LISTEN_FDS" -eq 2
38 test "$x" = "miaumiau"
40 # Upload another entry
41 T
="/dev/shm/fdstore.$RANDOM"
43 systemd-notify
--fd=3 --pid=parent
3<"$T"
46 # Check that no service is still around
47 test "$(systemctl show -P ActiveState testsuite-82-survive.service)" != "active"
48 test "$(systemctl show -P ActiveState testsuite-82-nosurvive.service)" != "active"
50 # Test that we really are in the new overlayfs root fs
53 cmp /etc
/os-release
/run
/systemd
/propagate
/.os-release-stage
/os-release
54 grep -q MARKER
=1 /etc
/os-release
56 # Switch back to the original root, away from the overlayfs
57 mount
--bind /original-root
/run
/nextroot
60 # Now issue the soft reboot. We should be right back soon.
61 touch /run
/testsuite82.touch3
62 systemctl
--no-block soft-reboot
64 # Now block until the soft-boot killing spree kills us
67 elif [ -f /run
/testsuite82.
touch ]; then
68 echo "This is the second boot!"
69 systemd-notify
--status="Second Boot"
71 # Clean up what we created earlier
72 rm /run
/testsuite82.
touch
74 # Check that the fdstore entry still exists
75 test "$LISTEN_FDS" -eq 1
77 test "$x" = "wuffwuff"
79 # Upload another entry
80 T
="/dev/shm/fdstore.$RANDOM"
82 systemd-notify
--fd=3 --pid=parent
3<"$T"
85 # Check that no service survived, regardless of the configuration
86 test "$(systemctl show -P ActiveState testsuite-82-survive.service)" != "active"
87 test "$(systemctl show -P ActiveState testsuite-82-nosurvive.service)" != "active"
89 # This time we test the /run/nextroot/ root switching logic. (We synthesize a new rootfs from the old via overlayfs)
90 mkdir
-p /run
/nextroot
/tmp
/nextroot-lower
/original-root
91 mount
-t tmpfs tmpfs
/tmp
/nextroot-lower
92 echo miep
>/tmp
/nextroot-lower
/lower
94 # Copy os-release away, so that we can manipulate it and check that it is updated in the propagate
95 # directory across soft reboots. Try to cover corner cases by truncating it.
96 mkdir
-p /tmp
/nextroot-lower
/usr
/lib
97 grep ID
/etc
/os-release
>/tmp
/nextroot-lower
/usr
/lib
/os-release
98 echo MARKER
=1 >>/tmp
/nextroot-lower
/usr
/lib
/os-release
99 cmp /etc
/os-release
/run
/systemd
/propagate
/.os-release-stage
/os-release
100 (! grep -q MARKER
=1 /etc
/os-release
)
102 mount
-t overlay nextroot
/run
/nextroot
-o lowerdir
=/tmp
/nextroot-lower
:/,ro
104 # Bind our current root into the target so that we later can return to it
105 mount
--bind / /run
/nextroot
/original-root
107 # Now issue the soft reboot. We should be right back soon.
108 touch /run
/testsuite82.touch2
109 systemctl
--no-block soft-reboot
111 # Now block until the soft-boot killing spree kills us
114 # This is the first boot
115 systemd-notify
--status="First Boot"
117 # Let's upload an fd to the fdstore, so that we can verify fdstore passing works correctly
118 T
="/dev/shm/fdstore.$RANDOM"
119 echo "wuffwuff" >"$T"
120 systemd-notify
--fd=3 --pid=parent
3<"$T"
123 # Create a script that can survive the soft reboot by ignoring SIGTERM (we
124 # do this instead of the argv[0][0] = '@' thing because that's so hard to
126 T
="/dev/shm/survive-$RANDOM.sh"
130 systemd-notify --ready
135 # This sets DefaultDependencies=no so that it remains running until the
136 # very end, and IgnoreOnIsolate=yes so that it isn't stopped via the
137 # "testsuite.target" isolation we do on next boot
138 systemd-run
-p Type
=notify
-p DefaultDependencies
=no
-p IgnoreOnIsolate
=yes --unit=testsuite-82-survive.service
"$T"
139 systemd-run
-p Type
=exec -p DefaultDependencies
=no
-p IgnoreOnIsolate
=yes --unit=testsuite-82-nosurvive.service
sleep infinity
141 # Now issue the soft reboot. We should be right back soon.
142 touch /run
/testsuite82.
touch
143 systemctl
--no-block soft-reboot
145 # Now block until the soft-boot killing spree kills us
149 systemd-analyze log-level info
152 systemctl
--no-block poweroff