#!/usr/bin/env bash # Install the Garage WAL archive on the Linode hub (10.10.0.5). Idempotent. # # sudo ./install.sh # # Installs: podman (if missing), /etc/garage/{garage.toml,garage.env}, # /etc/containers/systemd/garage.container, the nft guard, and the state dirs. # Then starts the unit and assigns the node's layout capacity on first run. # # The RPC secret is generated once and never printed. Rewriting it on an # existing install is harmless for a single-node store, but the copy in # /root/garage-backup is what a rebuild should reuse. set -euo pipefail here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) command -v podman >/dev/null || { export DEBIAN_FRONTEND=noninteractive apt-get update -qq apt-get install -y podman } install -d -m 0755 /etc/garage /etc/containers/systemd /etc/nftables.d install -d -m 0700 /var/lib/garage/meta /var/lib/garage/data install -m 0644 "$here/garage.toml" /etc/garage/garage.toml install -m 0644 "$here/garage.container" /etc/containers/systemd/garage.container if [ ! -s /etc/garage/garage.env ]; then umask 077 printf 'GARAGE_RPC_SECRET=%s\n' "$(openssl rand -hex 32)" > /etc/garage/garage.env fi chmod 0600 /etc/garage/garage.env # Guard first: the listener must never exist unguarded, not even for the # seconds between `compose/quadlet up` and a firewall install. "$here/host/install-wal-archive-firewall.sh" >/dev/null systemctl daemon-reload systemctl start garage.service # First run only: this Garage node needs a layout entry before it accepts # writes. Capacity 20 GB against a 79 GB disk holding 29 GB of other data — # see README "Disk sizing". for _ in $(seq 1 30); do garage_status=$(podman exec garage /garage -c /etc/garage.toml status 2>&1 || true) grep -q 'NO ROLE' <<<"$garage_status" && break sleep 2 done if grep -q 'NO ROLE' <<<"$garage_status"; then node_id=$(awk '/NO ROLE/{print $1}' <<<"$garage_status" | head -1) podman exec garage /garage -c /etc/garage.toml layout assign -z dc1 -c 20G "$node_id" podman exec garage /garage -c /etc/garage.toml layout apply --version 1 fi # Verify rather than assume. podman exec garage /garage -c /etc/garage.toml status ss -ltnH 'sport = :3900 or sport = :3903' nft list table inet wal_archive_guard >/dev/null && echo "OK: wal_archive_guard loaded"