2026-04-06 00:22:54 -03:00
|
|
|
#!/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.
|
2026-04-06 01:02:30 -03:00
|
|
|
Prefer a sibling cluster_power_recovery.sh when installed as a standalone helper.
|
|
|
|
|
Otherwise use a repo checkout if available, or delegate to another host.
|
2026-04-06 00:22:54 -03:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 01:02:30 -03:00
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
2026-04-06 00:22:54 -03:00
|
|
|
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
|
|
|
|
|
|
2026-04-06 01:02:30 -03:00
|
|
|
SIBLING_SCRIPT="${SCRIPT_DIR}/cluster_power_recovery.sh"
|
|
|
|
|
REPO_SCRIPT="${REPO_DIR}/scripts/cluster_power_recovery.sh"
|
|
|
|
|
LOCAL_SCRIPT=""
|
2026-04-06 00:22:54 -03:00
|
|
|
|
2026-04-06 01:02:30 -03:00
|
|
|
if [[ -x "${SIBLING_SCRIPT}" ]]; then
|
|
|
|
|
LOCAL_SCRIPT="${SIBLING_SCRIPT}"
|
|
|
|
|
elif [[ -x "${REPO_SCRIPT}" ]]; then
|
|
|
|
|
LOCAL_SCRIPT="${REPO_SCRIPT}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -n "${LOCAL_SCRIPT}" ]] && command -v kubectl >/dev/null 2>&1; then
|
2026-04-06 00:22:54 -03:00
|
|
|
exec "${LOCAL_SCRIPT}" "$@"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -z "${DELEGATE_HOST}" ]]; then
|
2026-04-06 01:02:30 -03:00
|
|
|
echo "cluster-power-console: no usable local recovery script found and no delegate host configured" >&2
|
2026-04-06 00:22:54 -03:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
quoted_args="$(printf '%q ' "$@")"
|
|
|
|
|
|
2026-04-06 01:02:30 -03:00
|
|
|
if [[ -r "${SIBLING_SCRIPT}" ]]; then
|
|
|
|
|
exec ssh -o BatchMode=yes -o ConnectTimeout=8 "${DELEGATE_HOST}" \
|
|
|
|
|
"bash -s -- ${quoted_args}" < "${SIBLING_SCRIPT}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -r "${REPO_SCRIPT}" ]]; then
|
|
|
|
|
exec ssh -o BatchMode=yes -o ConnectTimeout=8 "${DELEGATE_HOST}" \
|
|
|
|
|
"bash -s -- ${quoted_args}" < "${REPO_SCRIPT}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
quoted_repo_dir="$(printf '%q' "${REPO_DIR}")"
|
2026-04-06 00:22:54 -03:00
|
|
|
exec ssh -o BatchMode=yes -o ConnectTimeout=8 "${DELEGATE_HOST}" \
|
|
|
|
|
"cd ${quoted_repo_dir} && ./scripts/cluster_power_recovery.sh ${quoted_args}"
|