From 5dd3af70eb71db2fa3076a58c9bc8730877c0269 Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Wed, 5 Aug 2026 15:52:55 +1000 Subject: [PATCH] fix: rds handoff path --- scripts/images/rds-postgres/rds-agent.initd | 5 ++- .../rds-postgres/rds-agent_initd_test.sh | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 scripts/images/rds-postgres/rds-agent_initd_test.sh diff --git a/scripts/images/rds-postgres/rds-agent.initd b/scripts/images/rds-postgres/rds-agent.initd index 2878231a5..72caa5741 100644 --- a/scripts/images/rds-postgres/rds-agent.initd +++ b/scripts/images/rds-postgres/rds-agent.initd @@ -13,7 +13,6 @@ error_log="/var/log/rds-agent.log" start_stop_daemon_args="--wait 2000" AGENT_ENV="/etc/spinifex-rds/agent.env" -HANDOFF_ENV="${RDS_HANDOFF_DIR:-/run/spinifex-rds}/bootstrap.env" # The agent retries indefinitely, so this only bounds how long the boot waits # before letting rds-init fail visibly rather than hanging forever. @@ -42,6 +41,10 @@ start_pre() { } start_post() { + # Resolve this after start_pre loads agent.env so custom handoff directories + # are shared by the agent, this wait, and rds-init. + HANDOFF_ENV="${RDS_HANDOFF_DIR:-/run/spinifex-rds}/bootstrap.env" + # `before rds-init` only orders the starts; rds-init needs the fetched config # itself. The agent writes bootstrap.env last and renames it into place, so # its appearance means the whole handoff is there. diff --git a/scripts/images/rds-postgres/rds-agent_initd_test.sh b/scripts/images/rds-postgres/rds-agent_initd_test.sh new file mode 100644 index 000000000..6d9d63d64 --- /dev/null +++ b/scripts/images/rds-postgres/rds-agent_initd_test.sh @@ -0,0 +1,38 @@ +#!/bin/sh +set -eu + +SCRIPT_DIR=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd) +CASE=$(mktemp -d) +trap 'rm -rf "${CASE}"' EXIT + +source_time_handoff="${CASE}/source-time" +configured_handoff="${CASE}/configured" +mkdir -p "${configured_handoff}" +touch "${configured_handoff}/bootstrap.env" +printf 'RDS_HANDOFF_DIR=%s\n' "${configured_handoff}" >"${CASE}/agent.env" + +# Simulate OpenRC sourcing the service before start_pre loads agent.env. +export RDS_HANDOFF_DIR="${source_time_handoff}" +# shellcheck source=rds-agent.initd +. "${SCRIPT_DIR}/rds-agent.initd" +export AGENT_ENV="${CASE}/agent.env" +export handoff_timeout=0 + +EEND_STATUS= +ebegin() { :; } +einfo() { :; } +eend() { EEND_STATUS=$1; } + +start_pre +start_post + +if [ "${HANDOFF_ENV}" != "${configured_handoff}/bootstrap.env" ]; then + echo "FAIL: handoff path did not use RDS_HANDOFF_DIR from agent.env" >&2 + exit 1 +fi +if [ "${EEND_STATUS}" != "0" ]; then + echo "FAIL: post-start wait did not find the configured handoff" >&2 + exit 1 +fi + +echo "rds-agent.initd: all tests passed"