mirror of
https://github.com/community-scripts/ProxmoxVED.git
synced 2026-02-24 21:47:26 +00:00
Improve container install error handling and logging
Enhances reliability of application installation error detection in containers by using an error flag file, improves log copying and user prompts, and updates error handler to create a flag file with the exit code for host-side detection.
This commit is contained in:
@@ -2577,37 +2577,56 @@ EOF'
|
||||
install_ssh_keys_into_ct
|
||||
|
||||
# Run application installer
|
||||
if ! lxc-attach -n "$CTID" -- bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/install/${var_install}.sh)"; then
|
||||
local install_exit_code=$?
|
||||
lxc-attach -n "$CTID" -- bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/install/${var_install}.sh)"
|
||||
local lxc_exit=$?
|
||||
|
||||
# Check for error flag file in container (more reliable than lxc-attach exit code)
|
||||
local install_exit_code=0
|
||||
if [[ -n "${SESSION_ID:-}" ]]; then
|
||||
local error_flag="/root/.install-${SESSION_ID}.failed"
|
||||
if pct exec "$CTID" -- test -f "$error_flag" 2>/dev/null; then
|
||||
install_exit_code=$(pct exec "$CTID" -- cat "$error_flag" 2>/dev/null || echo "1")
|
||||
pct exec "$CTID" -- rm -f "$error_flag" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fallback to lxc-attach exit code if no flag file
|
||||
if [[ $install_exit_code -eq 0 && $lxc_exit -ne 0 ]]; then
|
||||
install_exit_code=$lxc_exit
|
||||
fi
|
||||
|
||||
# Installation failed?
|
||||
if [[ $install_exit_code -ne 0 ]]; then
|
||||
msg_error "Installation failed in container ${CTID} (exit code: ${install_exit_code})"
|
||||
|
||||
# Try to copy installation log from container before cleanup prompt
|
||||
# Try to copy installation log from container (without spinner/msg_info)
|
||||
if [[ -n "$CTID" && -n "${SESSION_ID:-}" ]]; then
|
||||
pct pull "$CTID" "/root/.install-${SESSION_ID}.log" "/tmp/install-${SESSION_ID}.log" 2>/dev/null || true
|
||||
msg_info "Installation log copied to /tmp/install-${SESSION_ID}.log"
|
||||
if pct pull "$CTID" "/root/.install-${SESSION_ID}.log" "/tmp/install-${SESSION_ID}.log" 2>/dev/null; then
|
||||
echo -e "${GN}✔${CL} Installation log: ${BL}/tmp/install-${SESSION_ID}.log${CL}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Prompt user for cleanup with 60s timeout
|
||||
local response
|
||||
# Prompt user for cleanup with 60s timeout (plain echo - no msg_info to avoid spinner)
|
||||
echo ""
|
||||
echo -en "${YW}Remove broken container ${CTID}? (Y/n) [auto-remove in 60s]: ${CL}"
|
||||
|
||||
if read -t 60 -r response; then
|
||||
if [[ -z "$response" || "$response" =~ ^[Yy]$ ]]; then
|
||||
# Remove container
|
||||
msg_info "Removing container ${CTID}"
|
||||
echo -e "\n${TAB}${HOLD}${YW}Removing container ${CTID}${CL}"
|
||||
pct stop "$CTID" &>/dev/null || true
|
||||
pct destroy "$CTID" &>/dev/null || true
|
||||
msg_ok "Container ${CTID} removed"
|
||||
echo -e "${BFR}${CM}${GN}Container ${CTID} removed${CL}"
|
||||
elif [[ "$response" =~ ^[Nn]$ ]]; then
|
||||
msg_info "Container ${CTID} kept for debugging"
|
||||
echo -e "\n${TAB}${YW}Container ${CTID} kept for debugging${CL}"
|
||||
fi
|
||||
else
|
||||
# Timeout - auto-remove
|
||||
echo -e "\n${YW}No response - auto-removing container${CL}"
|
||||
msg_info "Removing container ${CTID}"
|
||||
echo -e "${TAB}${HOLD}${YW}Removing container ${CTID}${CL}"
|
||||
pct stop "$CTID" &>/dev/null || true
|
||||
pct destroy "$CTID" &>/dev/null || true
|
||||
msg_ok "Container ${CTID} removed"
|
||||
echo -e "${BFR}${CM}${GN}Container ${CTID} removed${CL}"
|
||||
fi
|
||||
|
||||
exit $install_exit_code
|
||||
|
||||
Reference in New Issue
Block a user