Files
awx/cleanup.sh

45 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# cleanup.sh
# Stops known port-forward/service and optionally deletes the awx namespace and CRs.
PORTF_PID_FILE=${PORTF_PID_FILE:-/tmp/awx-pf.pid}
NAMESPACE=${NAMESPACE:-awx}
NONINTERACTIVE=${NONINTERACTIVE:-0}
echo "Looking for port-forward PID file: $PORTF_PID_FILE"
if [ -f "$PORTF_PID_FILE" ]; then
PID=$(cat "$PORTF_PID_FILE" 2>/dev/null || true)
if [ -n "$PID" ] && kill -0 "$PID" 2>/dev/null; then
echo "Stopping port-forward PID $PID"
kill "$PID" 2>/dev/null || true
else
echo "Stale PID file or process not running; removing PID file"
fi
rm -f "$PORTF_PID_FILE"
rm -f /tmp/awx-port-forward.log || true
else
echo "No port-forward PID file present"
fi
if [ "$NONINTERACTIVE" -eq 1 ]; then
yn=Y
else
read -r -p "Delete the AWX namespace and all AWX resources? [y/N]: " yn
fi
if [[ "$yn" =~ ^[Yy]$ ]]; then
echo "Deleting namespace $NAMESPACE"
if command -v kubectl >/dev/null 2>&1; then
kubectl delete ns "$NAMESPACE" --wait=true || true
else
echo "kubectl not found; skipping namespace delete" >&2
fi
echo "Note: CRDs are not deleted automatically. Remove them manually if desired."
else
echo "Skipping namespace deletion"
fi
echo "Cleanup complete."