From 0fd40b09d776eb6bde2b611a93b8994013f5d95d Mon Sep 17 00:00:00 2001 From: Roman Penyaev Date: Mon, 27 Nov 2023 11:39:30 +0100 Subject: [PATCH] pkg/xen-tools/init-initrd: don't poweroff if EVE_CONTAINER_NO_POWEROFF is set If container's init script misbehaves and exits, it becomes very difficult to debug such a container, because VM shuts down immediately by explicit poweroff call. This patch introduces an EVE_CONTAINER_NO_POWEROFF flag, which can be set in the application environment variables on the controller side and instead of calling /sbin/poweroff init-initrd sleeps infinitely, waiting for attention from a developer. Signed-off-by: Roman Penyaev --- pkg/xen-tools/initrd/init-initrd | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/xen-tools/initrd/init-initrd b/pkg/xen-tools/initrd/init-initrd index a0c010d44c..3aee612301 100755 --- a/pkg/xen-tools/initrd/init-initrd +++ b/pkg/xen-tools/initrd/init-initrd @@ -180,7 +180,18 @@ else #shellcheck disable=SC2086 eval /chroot2 /mnt/rootfs "${WORKDIR:-/}" $ug $pid_file $cmd <> /dev/console 2>&1 fi +chroot_ret=$? -# once the command exits -- the only thing left is shut everything down -echo "chroot2 exited with $?, the init-initrd is about to quit by calling /sbin/poweroff, which shuts the whole VM down" +# Container exited, final lines + +if test "$EVE_CONTAINER_NO_POWEROFF" = "1"; then + # Don't power off, wait for further debugging + echo "chroot2 exited with $chroot_ret, the init-initrd idles, please attach to the 'prime-cons' console of the hosting Vm for further debugging" + sleep infinity +else + # Power off is the default behavior + echo "chroot2 exited with $chroot_ret, the init-initrd is about to quit by calling /sbin/poweroff, which shuts the whole VM down" +fi + +# Do poweroff to avoid kernel panic on init exit /sbin/poweroff