nextwks.sh: add IMAP prompts, stop old containers in all modes, port conflict check, health check diagnostics

This commit is contained in:
Claus Lohmar 2026-07-11 00:21:21 +01:00
parent 2999f5da47
commit 1b24799026

View file

@ -83,6 +83,9 @@ if [ "$MODE" = "install" ]; then
read -sp "SMTP password: " SMTP_PASS; echo "" read -sp "SMTP password: " SMTP_PASS; echo ""
[ -z "$SMTP_PASS" ] && echo "ERROR: SMTP password required" && exit 1 [ -z "$SMTP_PASS" ] && echo "ERROR: SMTP password required" && exit 1
read -p "IMAP host [imap.openxchange.eu]: " IMAP_HOST; IMAP_HOST="${IMAP_HOST:-imap.openxchange.eu}"
read -p "IMAP port [993]: " IMAP_PORT; IMAP_PORT="${IMAP_PORT:-993}"
# Persist config to backup vault # Persist config to backup vault
mkdir -p "$BACKUP_DIR" mkdir -p "$BACKUP_DIR"
cat > "$BACKUP_DIR/.env" <<EOF cat > "$BACKUP_DIR/.env" <<EOF
@ -95,6 +98,8 @@ SMTP_HOST=$SMTP_HOST
SMTP_PORT=$SMTP_PORT SMTP_PORT=$SMTP_PORT
SMTP_USER=$SMTP_USER SMTP_USER=$SMTP_USER
SMTP_PASS=$SMTP_PASS SMTP_PASS=$SMTP_PASS
IMAP_HOST=$IMAP_HOST
IMAP_PORT=$IMAP_PORT
EOF EOF
chmod 600 "$BACKUP_DIR/.env" chmod 600 "$BACKUP_DIR/.env"
fi fi
@ -131,12 +136,10 @@ mkdir -p "$TARGET_DIR/config/caddy" "$TARGET_DIR/config/authelia" \
"$TARGET_DIR/config/nextworkspace" "$TARGET_DIR/logs" "$TARGET_DIR/config/nextworkspace" "$TARGET_DIR/logs"
# ============================================================ # ============================================================
# 5. TEARDOWN (destroy mode only) # 5. TEARDOWN (destroy mode only — wipes target dir)
# ============================================================ # ============================================================
if [ "$MODE" = "destroy" ]; then if [ "$MODE" = "destroy" ]; then
echo "[*] Full teardown..." echo "[*] Full teardown..."
podman stop caddy authelia launcher 2>/dev/null || true
podman rm caddy authelia launcher 2>/dev/null || true
rm -rf "$TARGET_DIR" rm -rf "$TARGET_DIR"
mkdir -p "$TARGET_DIR/config/caddy" "$TARGET_DIR/config/authelia" \ mkdir -p "$TARGET_DIR/config/caddy" "$TARGET_DIR/config/authelia" \
"$TARGET_DIR/data/caddy" "$TARGET_DIR/data/authelia" \ "$TARGET_DIR/data/caddy" "$TARGET_DIR/data/authelia" \
@ -210,7 +213,42 @@ if [ "$MODE" != "update" ]; then
fi fi
# ============================================================ # ============================================================
# 8. DEPLOY stack # 8. STOP old containers (all modes)
# ============================================================
echo "[*] Stopping any previous containers..."
for c in caddy authelia launcher; do
podman stop "$c" 2>/dev/null && echo " stopped $c" || true
podman rm "$c" 2>/dev/null && echo " removed $c" || true
done
sleep 1
# ============================================================
# 9. PORT CHECK — before deploy
# ============================================================
if ss -tlnp 2>/dev/null | grep -q ':80 '; then
echo "=============================================="
echo "[WARN] Port 80 is already in use."
ss -tlnp 2>/dev/null | grep ':80 '
echo ""
echo " This is usually Caddy from a previous run."
echo " Run this to stop it, then re-run deploy:"
echo " podman stop caddy && podman rm caddy"
echo "=============================================="
echo ""
read -p "Stop the container on port 80 now? [y/N]: " KILL
if [ "$KILL" = "y" ] || [ "$KILL" = "Y" ]; then
podman stop caddy 2>/dev/null || true
podman rm caddy 2>/dev/null || true
sleep 2
echo "[OK] Port 80 freed."
else
echo "[ABORT] Free port 80 first, then re-run."
exit 1
fi
fi
# ============================================================
# 10. DEPLOY stack
# ============================================================ # ============================================================
echo "[*] Deploying containers on $NETWORK_NAME..." echo "[*] Deploying containers on $NETWORK_NAME..."
@ -234,7 +272,7 @@ sleep 1
podman-compose -f "$TARGET_DIR/compose/stack.yaml" up -d 2>&1 || echo "[WARN] Stack deploy had issues" podman-compose -f "$TARGET_DIR/compose/stack.yaml" up -d 2>&1 || echo "[WARN] Stack deploy had issues"
# ============================================================ # ============================================================
# 9. HEALTH CHECK # 11. HEALTH CHECK
# ============================================================ # ============================================================
echo "[*] Running health check..." echo "[*] Running health check..."
for i in $(seq 1 $HEALTH_CHECK_RETRIES); do for i in $(seq 1 $HEALTH_CHECK_RETRIES); do
@ -248,4 +286,10 @@ for i in $(seq 1 $HEALTH_CHECK_RETRIES); do
done done
echo "[FAIL] Health check failed — launcher did not respond" echo "[FAIL] Health check failed — launcher did not respond"
echo ""
echo "--- Container status ---"
podman ps -a --filter "name=caddy|authelia|launcher" 2>/dev/null || true
echo ""
echo "--- Launcher logs (last 20 lines) ---"
podman logs launcher --tail 20 2>/dev/null || echo " (no logs)"
exit 1 exit 1