* [pve-devel] [PATCH installer v2] fix #5984: unconfigured: do not reboot if auto-installer fails by default
@ 2025-01-08 15:28 Daniel Kral
0 siblings, 0 replies; only message in thread
From: Daniel Kral @ 2025-01-08 15:28 UTC (permalink / raw)
To: pve-devel
An unintended side effect was introduced in 21ef304, which caused the
auto-installer to reboot on error, even though the answer file option
`general.reboot_on_error` has been set to `false`.
When an error signal is received inside `unconfigured.sh` (after the
trap statement `trap 'err_reboot' ERR`), it causes any failing command
to execute the `err_reboot` function and therefore dropping the user in
the debug shell. One exception, as described under `trap` in bash(1), is
for a command being part of the test in an if statement. Therefore, if
the auto-installer failed, it won't trap to `err_reboot`.
Therefore, create a flag file "/run/proxmox-reboot-on-error" if the
auto-installer should reboot on error. If it should, the auto-installer
will be rebooted on error. If not, artificially trap to `err_reboot` to
drop into the debug shell.
The shell check at `err_reboot` can now be removed since the function is
called directly.
Fixes: 21ef304 ("unconfigured.sh: run proxmox-post-hook after successful auto-install")
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
changes since v1 (thanks @Christoph):
- add a flag file "/run/proxmox-reboot-on-error"
- fix issue where `reboot_on_error` is ignored in general
- removing the shell check since `err_reboot` is called directly
---
Testing
I've tested this by booting the installer in debug mode, setting up DHCP
and patching the changes below. Otherwise I tested 8 possible scenarios,
where I simulated a failing auto install through trying to install a ZFS
RAID10 on only one disk and simulated a failing
post-installation-webhook by stopping the web server that handles the
POST request.
The following scenarios rebooted because of successful execution:
1. `reboot_on_error = false`, successful auto install
2. `reboot_on_error = false`, successful post-installation-webhook
3. `reboot_on_error = true`, successful auto install
4. `reboot_on_error = true`, successful post-installation-webhook
The following scenarios rebooted because of an error:
5. `reboot_on_error = true`, error during auto install
6. `reboot_on_error = true`, error during post-installation-webhook
And the following scenarios dropped into the debug shell:
7. `reboot_on_error = false`, error during auto install
8. `reboot_on_error = false`, error during post-installation-webhook
.../src/bin/proxmox-auto-installer.rs | 23 ++++++++-----------
unconfigured.sh | 14 ++++++++---
2 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
index ece9a94..22c727b 100644
--- a/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
+++ b/proxmox-auto-installer/src/bin/proxmox-auto-installer.rs
@@ -117,25 +117,20 @@ fn main() -> ExitCode {
}
};
+ if answer.global.reboot_on_error {
+ let _ = File::create("/run/proxmox-reboot-on-error");
+ }
+
match run_installation(&answer, &locales, &runtime_info, &udevadm_info, &setup_info) {
- Ok(_) => info!("Installation done."),
+ Ok(_) => {
+ info!("Installation done.");
+ ExitCode::SUCCESS
+ },
Err(err) => {
error!("Installation failed: {err:#}");
- return exit_failure(answer.global.reboot_on_error);
+ ExitCode::FAILURE
}
}
-
- ExitCode::SUCCESS
-}
-
-/// When we exit with a failure, the installer will not automatically reboot.
-/// Default value for reboot_on_error is false
-fn exit_failure(reboot_on_error: bool) -> ExitCode {
- if reboot_on_error {
- ExitCode::SUCCESS
- } else {
- ExitCode::FAILURE
- }
}
fn run_installation(
diff --git a/unconfigured.sh b/unconfigured.sh
index 070cf33..4a8f09f 100755
--- a/unconfigured.sh
+++ b/unconfigured.sh
@@ -104,7 +104,6 @@ real_reboot() {
}
# reachable through the ERR trap
-# shellcheck disable=SC2317
err_reboot() {
printf "\nInstallation aborted - unable to continue (type exit or CTRL-D to reboot)\n"
debugsh || true
@@ -254,12 +253,21 @@ elif [ $start_auto_installer -ne 0 ]; then
fi
echo "Starting automatic installation"
+ # creates "/run/proxmox-reboot-on-error" if `global.reboot_on_error = true`
if /usr/bin/proxmox-auto-installer </run/automatic-installer-answers; then
if ! /usr/bin/proxmox-post-hook </run/automatic-installer-answers; then
echo "post installation hook failed to execute."
- echo "waiting 30s to allow gathering the error before reboot."
- sleep 30
+
+ # drop into debug shell if it shouldn't reboot on error
+ if [ ! -f /run/proxmox-reboot-on-error ]; then
+ err_reboot
+ else
+ echo "waiting 30s to allow gathering the error before reboot."
+ sleep 30
+ fi
fi
+ elif [ ! -f /run/proxmox-reboot-on-error ]; then
+ err_reboot
fi
else
echo "Starting the installer GUI - see tty2 (CTRL+ALT+F2) for any errors..."
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-01-08 15:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-08 15:28 [pve-devel] [PATCH installer v2] fix #5984: unconfigured: do not reboot if auto-installer fails by default Daniel Kral
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox