Enhance build-cloudinit-image.sh with improved error handling for decompression: add checks for xz installation, validate downloaded file type, and capture detailed error messages during decompression failures. Update deploy-to-proxmox.sh to restart cm4-dashboard service after enabling it, ensuring new code is loaded.
This commit is contained in:
@@ -66,8 +66,27 @@ if ! curl "${CURL_OPTS[@]}" "$URL" 2>"$CURL_ERR"; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
write_status "decompressing" "Decompressing image…" "" ""
|
write_status "decompressing" "Decompressing image…" "" ""
|
||||||
|
# Check we have a real xz file (not HTML error page)
|
||||||
|
if ! command -v xz >/dev/null 2>&1; then
|
||||||
|
write_status "error" "" "" "Decompress failed: xz not installed. Install xz-utils (apt install xz-utils)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ ! -s "$XZ_FILE" ]]; then
|
||||||
|
write_status "error" "" "" "Decompress failed: downloaded file is empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
FILE_TYPE=$(file -b "$XZ_FILE" 2>/dev/null || true)
|
||||||
|
if [[ "$FILE_TYPE" == *"HTML"* ]] || [[ "$FILE_TYPE" == *"text"* ]] && [[ "$FILE_TYPE" != *"XZ"* ]]; then
|
||||||
|
write_status "error" "" "" "Decompress failed: download is not an image (got: ${FILE_TYPE:0:80})"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
IMG_FILE="$TEMP_DIR/image.img"
|
IMG_FILE="$TEMP_DIR/image.img"
|
||||||
xz -d -k -f "$XZ_FILE" || { write_status "error" "" "" "Decompress failed"; exit 1; }
|
XZ_ERR="$TEMP_DIR/xz_err.txt"
|
||||||
|
if ! xz -d -k -f "$XZ_FILE" 2>"$XZ_ERR"; then
|
||||||
|
err_detail=$(head -c 300 "$XZ_ERR" 2>/dev/null | tr '\n' ' ' | sed 's/"/\\"/g')
|
||||||
|
write_status "error" "" "" "Decompress failed: ${err_detail:-xz exited with error}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
[[ -f "$IMG_FILE" ]] || { write_status "error" "" "" "image.img not found after decompress"; exit 1; }
|
[[ -f "$IMG_FILE" ]] || { write_status "error" "" "" "image.img not found after decompress"; exit 1; }
|
||||||
|
|
||||||
write_status "injecting" "Mounting boot partition and injecting cloud-init…" "" ""
|
write_status "injecting" "Mounting boot partition and injecting cloud-init…" "" ""
|
||||||
|
|||||||
@@ -317,7 +317,8 @@ fi
|
|||||||
pct exec "$CTID" -- cp /opt/cm4-provisioning/dashboard/cm4-dashboard.service /etc/systemd/system/
|
pct exec "$CTID" -- cp /opt/cm4-provisioning/dashboard/cm4-dashboard.service /etc/systemd/system/
|
||||||
pct exec "$CTID" -- systemctl daemon-reload
|
pct exec "$CTID" -- systemctl daemon-reload
|
||||||
pct exec "$CTID" -- systemctl enable --now cm4-dashboard
|
pct exec "$CTID" -- systemctl enable --now cm4-dashboard
|
||||||
log "LXC: cm4-dashboard enabled and started."
|
pct exec "$CTID" -- systemctl restart cm4-dashboard
|
||||||
|
log "LXC: cm4-dashboard enabled and restarted (new code loaded)."
|
||||||
|
|
||||||
# --- LXC: optional SSH (root password + SSH key from deploy env) ---
|
# --- LXC: optional SSH (root password + SSH key from deploy env) ---
|
||||||
if [[ -n "${DEPLOY_SSH_KEY_B64:-}" ]] || [[ -n "${DEPLOY_LXC_PWD_B64:-}" ]]; then
|
if [[ -n "${DEPLOY_SSH_KEY_B64:-}" ]] || [[ -n "${DEPLOY_LXC_PWD_B64:-}" ]]; then
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Run on the Proxmox host (root@10.130.60.224) to diagnose cloud-init build failures.
|
||||||
|
# Usage: scp this script to the host, then: bash troubleshoot-cloudinit-build.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
echo "=== Cloud-init build troubleshoot ==="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "1. xz available?"
|
||||||
|
if command -v xz >/dev/null 2>&1; then
|
||||||
|
xz --version | head -1
|
||||||
|
else
|
||||||
|
echo " NOT FOUND. Install: apt install -y xz-utils"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "2. /tmp space (need several GB for decompress)?"
|
||||||
|
df -h /tmp
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "3. Provisioning dir and last request?"
|
||||||
|
PROV_DIR="${CM4_PROVISIONING_DIR:-/var/lib/cm4-provisioning}"
|
||||||
|
[[ -f /opt/cm4-provisioning/env ]] && source /opt/cm4-provisioning/env
|
||||||
|
echo " PROV_DIR=$PROV_DIR"
|
||||||
|
if [[ -f "$PROV_DIR/build_cloudinit_request.json" ]]; then
|
||||||
|
echo " Last request URL: $(python3 -c "import json; print(json.load(open('$PROV_DIR/build_cloudinit_request.json')).get('url','?'))" 2>/dev/null || echo '?')"
|
||||||
|
else
|
||||||
|
echo " No request file (build may have already run)."
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "4. Last build status?"
|
||||||
|
if [[ -f "$PROV_DIR/build_cloudinit_status.json" ]]; then
|
||||||
|
cat "$PROV_DIR/build_cloudinit_status.json" | python3 -m json.tool 2>/dev/null || cat "$PROV_DIR/build_cloudinit_status.json"
|
||||||
|
else
|
||||||
|
echo " No status file."
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
TEST_DIR=$(mktemp -d)
|
||||||
|
trap "rm -rf $TEST_DIR" EXIT
|
||||||
|
echo "5. Quick xz decompress test?"
|
||||||
|
echo "test content" > "$TEST_DIR/f.txt"
|
||||||
|
xz -k "$TEST_DIR/f.txt" 2>/dev/null && xz -d -k -f "$TEST_DIR/f.txt.xz" 2>/dev/null && echo " OK" || echo " FAILED"
|
||||||
|
echo ""
|
||||||
|
echo "Done. If xz is missing, run on host: apt update && apt install -y xz-utils"
|
||||||
Reference in New Issue
Block a user