Make first deployment race-safe
This commit is contained in:
@@ -109,6 +109,51 @@ if [[ -n "$WM_REMOTE_SUDO" ]]; then
|
||||
rsync_path="$WM_REMOTE_SUDO rsync"
|
||||
fi
|
||||
|
||||
wait_for_remote_release() {
|
||||
local expected_revision="$1"
|
||||
local timeout_seconds="${WATERMAPS_RELEASE_WAIT_SECONDS:-43200}"
|
||||
local poll_seconds="${WATERMAPS_RELEASE_POLL_SECONDS:-15}"
|
||||
local deadline
|
||||
local attempts=0
|
||||
local remote_check
|
||||
|
||||
[[ "$timeout_seconds" =~ ^[1-9][0-9]*$ ]] &&
|
||||
((timeout_seconds >= 60 && timeout_seconds <= 46800)) ||
|
||||
wm_local_die "WATERMAPS_RELEASE_WAIT_SECONDS muss zwischen 60 und 46800 liegen."
|
||||
[[ "$poll_seconds" =~ ^[1-9][0-9]*$ ]] &&
|
||||
((poll_seconds >= 5 && poll_seconds <= 60)) ||
|
||||
wm_local_die "WATERMAPS_RELEASE_POLL_SECONDS muss zwischen 5 und 60 liegen."
|
||||
deadline=$((SECONDS + timeout_seconds))
|
||||
|
||||
remote_check="${remote_prefix}test -L /opt/watermaps/current"
|
||||
remote_check+=" && ${remote_prefix}grep -Fxq"
|
||||
remote_check+=" 'WATERMAPS_DEPLOY_REVISION=$expected_revision'"
|
||||
remote_check+=" /opt/watermaps/deploy/.env.images"
|
||||
remote_check+=" && ${remote_prefix}readlink --canonicalize /opt/watermaps/current"
|
||||
remote_check+=" | grep -Eq '/$expected_revision$'"
|
||||
|
||||
while ((SECONDS < deadline)); do
|
||||
if ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" "$remote_check" \
|
||||
>/dev/null 2>&1; then
|
||||
printf '[watermaps] Commit %s ist auf dem Server aktiv.\n' \
|
||||
"$expected_revision"
|
||||
return 0
|
||||
fi
|
||||
|
||||
attempts=$((attempts + 1))
|
||||
if ((attempts == 1 || attempts % 4 == 0)); then
|
||||
printf '[watermaps] Das revisionsgenaue Erstdeployment läuft unter systemd; warte auf Commit %s …\n' \
|
||||
"$expected_revision"
|
||||
fi
|
||||
sleep "$poll_seconds"
|
||||
done
|
||||
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" \
|
||||
"${remote_prefix}systemctl --no-pager --full status watermaps-auto-deploy.service" \
|
||||
|| true
|
||||
wm_local_die "Commit $expected_revision wurde nicht innerhalb von ${timeout_seconds}s aktiviert."
|
||||
}
|
||||
|
||||
printf '[watermaps] Warte auf Cloud-init und das persistente Hetzner-Volume.\n'
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" \
|
||||
"cloud-init status --wait && ${remote_prefix}systemctl start watermaps-volume-setup.service && mountpoint --quiet /srv/watermaps-data"
|
||||
@@ -148,10 +193,9 @@ fi
|
||||
|
||||
remote_command="${remote_prefix}chmod +x /opt/watermaps/deploy/scripts/*.sh"
|
||||
remote_command+=" && ${remote_prefix}/opt/watermaps/deploy/scripts/bootstrap-server.sh"
|
||||
remote_command+=" && ${remote_prefix}WATERMAPS_ENV_FILE=/opt/watermaps/deploy/.env.production /opt/watermaps/deploy/scripts/auto-deploy.sh"
|
||||
remote_command+=" && ${remote_prefix}test -L /opt/watermaps/current"
|
||||
remote_command+=" && ${remote_prefix}grep -Fxq 'WATERMAPS_DEPLOY_REVISION=$revision' /opt/watermaps/deploy/.env.images"
|
||||
remote_command+=" && ${remote_prefix}systemctl start --no-block watermaps-auto-deploy.service"
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" "$remote_command"
|
||||
wait_for_remote_release "$revision"
|
||||
|
||||
if [[ "$run_go_live" == "true" ]]; then
|
||||
ssh "${WM_SSH_OPTIONS[@]}" "$WM_SSH_TARGET" \
|
||||
|
||||
Reference in New Issue
Block a user