From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer v2] fix #5984: unconfigured: do not reboot if auto-installer fails by default
Date: Wed, 8 Jan 2025 16:28:28 +0100 [thread overview]
Message-ID: <20250108152828.232648-1-d.kral@proxmox.com> (raw)
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
next reply other threads:[~2025-01-08 15:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-08 15:28 Daniel Kral [this message]
2025-02-24 15:19 ` [pve-devel] applied: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250108152828.232648-1-d.kral@proxmox.com \
--to=d.kral@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.