Add homelab-wide service startup
This commit is contained in:
parent
0c2e9d9d06
commit
9a3e04f4d9
|
|
@ -29,7 +29,7 @@ var allowedCommands = map[string]bool{
|
|||
"help": true, "up": true, "plan": true,
|
||||
"cluster-profile": true, "rebuild-cluster": true, "stop-cluster": true,
|
||||
"start-cluster": true, "cleanup-debian-k8s": true,
|
||||
"shutdown": true,
|
||||
"shutdown": true, "start": true,
|
||||
"status": true, "capacity": true, "capacity-advisor": true,
|
||||
"capacity-limits": true, "recover-plan": true, "gitops-status": true,
|
||||
"gitops": true,
|
||||
|
|
|
|||
5
jeannie
5
jeannie
|
|
@ -86,6 +86,7 @@ Cluster Lifecycle
|
|||
stop-cluster Stop Kubernetes and worker VMs without destroy.
|
||||
start-cluster Start Kubernetes and desired worker VMs.
|
||||
shutdown {plan|apply --yes} Stop homelab services on every managed host; keep Jeannie API.
|
||||
start {plan|apply} Start homelab services on every managed host.
|
||||
cleanup-debian-k8s Remove old Debian kubeadm runtime after Pimox offload.
|
||||
workers <list|tailnet|start|stop|restart|drain|uncordon|recreate-plan|rebalance|disk-status|disk-cleanup>
|
||||
Manage Pimox/Kubernetes workers.
|
||||
|
|
@ -253,6 +254,10 @@ case "${1:-}" in
|
|||
record_change_journal "shutdown" "$@"
|
||||
homelab_shutdown "${@:2}"
|
||||
;;
|
||||
start)
|
||||
record_change_journal "start" "$@"
|
||||
homelab_start "${@:2}"
|
||||
;;
|
||||
start-cluster)
|
||||
record_change_journal "start-cluster" "$@"
|
||||
start_cluster
|
||||
|
|
|
|||
|
|
@ -763,6 +763,44 @@ else
|
|||
fi"
|
||||
}
|
||||
|
||||
start_remote_compose_stack() {
|
||||
local label="$1"
|
||||
local target="$2"
|
||||
local install_dir="$3"
|
||||
local key_path="${4:-}"
|
||||
local ssh_args=(-o BatchMode=yes -o ConnectTimeout=15 -o StrictHostKeyChecking=accept-new)
|
||||
|
||||
[[ -n "${key_path}" ]] && ssh_args+=(-i "${key_path}")
|
||||
echo "--> Starting ${label} services on ${target} (${install_dir})..."
|
||||
ssh "${ssh_args[@]}" "${target}" "
|
||||
set -eu
|
||||
if [ -f '${install_dir}/docker-compose.yml' ] || [ -f '${install_dir}/compose.yml' ]; then
|
||||
cd '${install_dir}'
|
||||
if sudo docker compose version >/dev/null 2>&1; then
|
||||
sudo docker compose start || sudo docker compose up -d --remove-orphans
|
||||
elif command -v docker-compose >/dev/null 2>&1; then
|
||||
sudo docker-compose start || sudo docker-compose up -d --remove-orphans
|
||||
else
|
||||
echo 'Docker Compose is unavailable.' >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo '${install_dir}/docker-compose.yml not found.' >&2
|
||||
exit 1
|
||||
fi"
|
||||
}
|
||||
|
||||
start_bastion_compose_stack() {
|
||||
local label="$1" bastion_id="$2" instance_id="$3" user="$4" public_key="$5" private_key="$6" install_dir="$7"
|
||||
[[ -n "${bastion_id}" && -n "${instance_id}" ]] || {
|
||||
echo "${label} Bastion target is not configured; cannot start through the private path." >&2
|
||||
return 1
|
||||
}
|
||||
echo "--> Starting ${label} services through OCI Bastion (${instance_id})..."
|
||||
"${REPO_ROOT}/scripts/oci-bastion-ssh" --command "cd '${install_dir}' && (sudo docker compose start || sudo docker compose up -d --remove-orphans)" \
|
||||
"${bastion_id}" "${instance_id}" "${user}" "${public_key}" "${private_key}"
|
||||
}
|
||||
|
||||
shutdown_rpi_services() {
|
||||
local rpi_host="${LAB_RPI_HOST:-${LAB_RASPBERRY_HOST:-192.168.100.89}}"
|
||||
local rpi_user="${LAB_RPI_USER:-${LAB_RASPBERRY_USER:-jv}}"
|
||||
|
|
@ -827,6 +865,105 @@ shutdown_debian_services() {
|
|||
fi
|
||||
}
|
||||
|
||||
start_debian_services() {
|
||||
echo "--> Starting Debian homelab services (jeannie-server is already preserved)..."
|
||||
sudo systemctl start docker 2>/dev/null || true
|
||||
sudo systemctl start \
|
||||
jeannie-eventd.service \
|
||||
jeannie-temporal-worker.service \
|
||||
homelab-edge-traefik-route.service \
|
||||
homelab-pimox-registry-forward.service \
|
||||
homelab-gitea-runner.service \
|
||||
homelab-gitea-backup.service \
|
||||
homelab-gitea-restore-drill.service \
|
||||
homelab-profile-backup.service \
|
||||
2>/dev/null || true
|
||||
local containers
|
||||
containers="$(sudo docker ps -aq 2>/dev/null || true)"
|
||||
if [[ -n "${containers}" ]]; then
|
||||
echo "Starting Debian Docker container(s)..."
|
||||
printf '%s\n' "${containers}" | xargs -r sudo docker start >/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
start_rpi_services() {
|
||||
local rpi_host="${LAB_RPI_HOST:-${LAB_RASPBERRY_HOST:-192.168.100.89}}"
|
||||
local rpi_user="${LAB_RPI_USER:-${LAB_RASPBERRY_USER:-jv}}"
|
||||
local rpi_key="${LAB_RPI_SSH_KEY_PATH:-${LAB_RASPBERRY_SSH_KEY_PATH:-${HOME}/.ssh/id_ed25519}}"
|
||||
local install_dir="${LAB_RPI_SERVICES_INSTALL_DIR:-/opt/homelab-rpi-services}"
|
||||
start_remote_compose_stack "RPi4" "${rpi_user}@${rpi_host}" "${install_dir}" "${rpi_key}"
|
||||
}
|
||||
|
||||
start_oci_edge_services() {
|
||||
local edge_host="${LAB_EDGE_HOST:-${LAB_OCI_EDGE_PUBLIC_IP:-}}"
|
||||
local edge_user="${LAB_EDGE_USER:-ubuntu}"
|
||||
local edge_key="${LAB_EDGE_SSH_KEY_PATH:-${LAB_OCI_SSH_PRIVATE_KEY:-${HOME}/.ssh/id_ed25519}}"
|
||||
local install_dir="${LAB_EDGE_INSTALL_DIR:-/opt/homelab-edge}"
|
||||
if truthy "${LAB_OCI_BASTION_ENABLED:-true}" && [[ -n "${LAB_OCI_BASTION_ID:-}" && -n "${LAB_OCI_EDGE_INSTANCE_ID:-}" ]]; then
|
||||
start_bastion_compose_stack "OCI edge" "${LAB_OCI_BASTION_ID}" "${LAB_OCI_EDGE_INSTANCE_ID}" "${edge_user}" "${edge_key}.pub" "${edge_key}" "${install_dir}"
|
||||
else
|
||||
[[ -n "${edge_host}" ]] || { echo "OCI edge host is not configured." >&2; return 1; }
|
||||
start_remote_compose_stack "OCI edge" "${edge_user}@${edge_host}" "${install_dir}" "${edge_key}"
|
||||
fi
|
||||
}
|
||||
|
||||
start_oci_email_services() {
|
||||
local email_host="${LAB_EMAIL_PUBLIC_IP:-${LAB_OCI_EMAIL_PUBLIC_IP:-}}"
|
||||
local email_user="${LAB_EMAIL_SSH_USER:-ubuntu}"
|
||||
local email_key="${LAB_EMAIL_SSH_PRIVATE_KEY:-${HOME}/.ssh/id_ed25519}"
|
||||
if [[ -z "${email_host}" ]]; then
|
||||
email_host="$(tofu -chdir="${REPO_ROOT}/bootstrap/oci" output -raw email_public_ip 2>/dev/null || true)"
|
||||
fi
|
||||
[[ -n "${email_host}" && "${email_host}" != "null" ]] || { echo "OCI email host is not configured; skipping mail VM."; return 0; }
|
||||
if truthy "${LAB_OCI_BASTION_ENABLED:-true}" && [[ -n "${LAB_OCI_BASTION_ID:-}" && -n "${LAB_OCI_EMAIL_INSTANCE_ID:-}" ]]; then
|
||||
echo "--> Starting OCI email services through OCI Bastion..."
|
||||
"${REPO_ROOT}/scripts/oci-bastion-ssh" --command "sudo systemctl start postfix dovecot fail2ban prometheus-node-exporter 2>/dev/null || true" \
|
||||
"${LAB_OCI_BASTION_ID}" "${LAB_OCI_EMAIL_INSTANCE_ID}" "${email_user}" "${email_key}.pub" "${email_key}"
|
||||
else
|
||||
echo "--> Starting OCI email services on ${email_user}@${email_host}..."
|
||||
ssh -i "${email_key}" -o BatchMode=yes -o ConnectTimeout=15 -o StrictHostKeyChecking=accept-new \
|
||||
"${email_user}@${email_host}" \
|
||||
"sudo systemctl start postfix dovecot fail2ban prometheus-node-exporter 2>/dev/null || true"
|
||||
fi
|
||||
}
|
||||
|
||||
homelab_start() {
|
||||
local action="${1:-plan}"
|
||||
local failures=0
|
||||
case "${action}" in
|
||||
plan)
|
||||
cat <<'EOF'
|
||||
Homelab startup plan
|
||||
====================
|
||||
Start Debian services and containers, Kubernetes/Pimox, RPi4 services,
|
||||
OCI edge services, and OCI email services. Existing disks and configuration
|
||||
are preserved; already-running services are left unchanged.
|
||||
|
||||
Run ./jeannie start apply to execute this plan.
|
||||
EOF
|
||||
;;
|
||||
apply)
|
||||
require_debian_server "start"
|
||||
echo "Starting all managed homelab services..."
|
||||
start_debian_services || failures=$((failures + 1))
|
||||
start_cluster || failures=$((failures + 1))
|
||||
start_rpi_services || failures=$((failures + 1))
|
||||
start_oci_edge_services || failures=$((failures + 1))
|
||||
start_oci_email_services || failures=$((failures + 1))
|
||||
if systemctl is-active --quiet jeannie-server.service 2>/dev/null; then
|
||||
echo "PASS jeannie-server.service is active."
|
||||
else
|
||||
echo "FAIL jeannie-server.service is not active." >&2
|
||||
failures=$((failures + 1))
|
||||
fi
|
||||
((failures == 0)) || { echo "Homelab startup finished with ${failures} failure(s)." >&2; return 1; }
|
||||
echo "Homelab services started."
|
||||
;;
|
||||
--help|help) echo "Usage: ./jeannie start {plan|apply}" ;;
|
||||
*) echo "Usage: ./jeannie start {plan|apply}" >&2; return 2 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
homelab_shutdown() {
|
||||
local action="${1:-plan}"
|
||||
local failures=0
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ set -euo pipefail
|
|||
print_command=false
|
||||
public_key_material=""
|
||||
private_key_override=""
|
||||
remote_command=""
|
||||
if [[ "${1:-}" == "ssh" ]]; then
|
||||
shift
|
||||
fi
|
||||
|
|
@ -12,6 +13,7 @@ while (($# > 0)); do
|
|||
--print-command) print_command=true; shift ;;
|
||||
--public-key) public_key_material="${2:-}"; shift 2 ;;
|
||||
--private-key-path) private_key_override="${2:-}"; shift 2 ;;
|
||||
--command) remote_command="${2:-}"; shift 2 ;;
|
||||
--) shift; break ;;
|
||||
*) break ;;
|
||||
esac
|
||||
|
|
@ -72,6 +74,9 @@ ssh_command="$("${oci_bin}" bastion session get \
|
|||
--query 'data."ssh-metadata".command' \
|
||||
--raw-output)"
|
||||
ssh_command="${ssh_command//<privateKey>/${private_key}}"
|
||||
if [[ -n "${remote_command}" ]]; then
|
||||
ssh_command+=" -- ${remote_command}"
|
||||
fi
|
||||
if [[ "${print_command}" == true ]]; then
|
||||
printf 'session_id=%s\n' "${session_id}"
|
||||
printf 'ssh_command=%s\n' "${ssh_command}"
|
||||
|
|
|
|||
Loading…
Reference in New Issue