Skip to content

Commit

Permalink
pkg/xen-tools/init-initrd: don't poweroff if EVE_CONTAINER_NO_POWEROF…
Browse files Browse the repository at this point in the history
…F 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 <[email protected]>
  • Loading branch information
rouming committed Nov 27, 2023
1 parent 57b5e93 commit 0fd40b0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/xen-tools/initrd/init-initrd
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0fd40b0

Please sign in to comment.