69 lines
1.7 KiB
Bash
69 lines
1.7 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
usage() {
|
||
|
|
cat <<'USAGE'
|
||
|
|
Usage:
|
||
|
|
scripts/cluster_power_console.sh [--repo-dir <path>] [--delegate-host <host>] <shutdown|startup> [recovery-script-options...]
|
||
|
|
|
||
|
|
Purpose:
|
||
|
|
Friendly manual entrypoint for running cluster power recovery from a remote console.
|
||
|
|
If the repo checkout exists locally, run the recovery script here.
|
||
|
|
Otherwise, delegate to another host that has the repo checkout.
|
||
|
|
|
||
|
|
Defaults:
|
||
|
|
--repo-dir $HOME/Development/titan-iac
|
||
|
|
--delegate-host titan-24
|
||
|
|
|
||
|
|
Examples:
|
||
|
|
scripts/cluster_power_console.sh shutdown --execute
|
||
|
|
scripts/cluster_power_console.sh startup --execute --force-flux-branch main
|
||
|
|
scripts/cluster_power_console.sh --delegate-host titan-24 shutdown --execute
|
||
|
|
USAGE
|
||
|
|
}
|
||
|
|
|
||
|
|
REPO_DIR="${HOME}/Development/titan-iac"
|
||
|
|
DELEGATE_HOST="titan-24"
|
||
|
|
|
||
|
|
while [[ $# -gt 0 ]]; do
|
||
|
|
case "$1" in
|
||
|
|
--repo-dir)
|
||
|
|
REPO_DIR="${2:-}"
|
||
|
|
shift 2
|
||
|
|
;;
|
||
|
|
--delegate-host)
|
||
|
|
DELEGATE_HOST="${2:-}"
|
||
|
|
shift 2
|
||
|
|
;;
|
||
|
|
-h|--help)
|
||
|
|
usage
|
||
|
|
exit 0
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
break
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
done
|
||
|
|
|
||
|
|
if [[ $# -lt 1 ]]; then
|
||
|
|
usage
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
LOCAL_SCRIPT="${REPO_DIR}/scripts/cluster_power_recovery.sh"
|
||
|
|
|
||
|
|
if [[ -x "${LOCAL_SCRIPT}" ]] && command -v kubectl >/dev/null 2>&1; then
|
||
|
|
exec "${LOCAL_SCRIPT}" "$@"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [[ -z "${DELEGATE_HOST}" ]]; then
|
||
|
|
echo "cluster-power-console: local repo checkout not found at ${REPO_DIR} and no delegate host configured" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
quoted_repo_dir="$(printf '%q' "${REPO_DIR}")"
|
||
|
|
quoted_args="$(printf '%q ' "$@")"
|
||
|
|
|
||
|
|
exec ssh -o BatchMode=yes -o ConnectTimeout=8 "${DELEGATE_HOST}" \
|
||
|
|
"cd ${quoted_repo_dir} && ./scripts/cluster_power_recovery.sh ${quoted_args}"
|