From ff80f5bf973145dbe2a07047c070c10d1b7d9bb7 Mon Sep 17 00:00:00 2001 From: Gregor Klevze Date: Sat, 29 Aug 2026 14:12:51 +0200 Subject: [PATCH] Rollback comments observer margin --- scripts/_probe_ssr.sh | 21 +++++++ scripts/sync-safe-updated.sh | 105 +++++++++++++++++++---------------- 2 files changed, 78 insertions(+), 48 deletions(-) create mode 100644 scripts/_probe_ssr.sh diff --git a/scripts/_probe_ssr.sh b/scripts/_probe_ssr.sh new file mode 100644 index 00000000..c7986dfc --- /dev/null +++ b/scripts/_probe_ssr.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set +e +ssh_bin=ssh +remote_server=klevze@server3.klevze.si +key=/tmp/skinbase-deploy-ssh/identities/id_ed25519 +opts=(-o BatchMode=yes -o StrictHostKeyChecking=accept-new -o ConnectTimeout=15 -o IdentitiesOnly=yes) +if [[ -S /tmp/skinbase-deploy-ssh/mux-klevze_server3.klevze.si.sock ]]; then + opts+=(-o ControlPath=/tmp/skinbase-deploy-ssh/mux-klevze_server3.klevze.si.sock) +fi +if [[ -f "$key" ]]; then + opts+=(-i "$key") +fi + +"$ssh_bin" "${opts[@]}" "$remote_server" 'sudo -n -l' +echo EXIT:$? +echo '--- ps ---' +"$ssh_bin" "${opts[@]}" "$remote_server" "ps -ef | grep -E 'ssr|inertia|supervisor' | grep -v grep" +echo '--- status ---' +"$ssh_bin" "${opts[@]}" "$remote_server" 'sudo -n /usr/bin/supervisorctl status' +echo '--- restart ---' +"$ssh_bin" "${opts[@]}" "$remote_server" 'sudo -n /usr/bin/supervisorctl restart skinbase-ssr; echo rc=$?' diff --git a/scripts/sync-safe-updated.sh b/scripts/sync-safe-updated.sh index 9b0684a1..10c79e95 100644 --- a/scripts/sync-safe-updated.sh +++ b/scripts/sync-safe-updated.sh @@ -1086,6 +1086,60 @@ printf ' -> Pointed %s at %s\n' "$REMOTE_FOLDER" "$CURRENT_LINK" EOF_PUBLIC_LINK } +# Supervisor listens on a root socket. The app user (skinbase) cannot talk to it, +# and artisan inertia:start-ssr fights the supervised process. Restart as the +# SSH login user with passwordless sudo supervisorctl. +restart_remote_inertia_ssr() { + [[ "$skip_ssr_restart" -eq 0 ]] || return 0 + + log_step "Restarting Inertia SSR via Supervisor ($ssr_supervisor_program)" + + ssh_remote "$remote_server" env \ + SSR_PROGRAM="$(printf '%q' "$ssr_supervisor_program")" \ + bash -s <<'EOF_SSR_RESTART' +set -euo pipefail +cd /tmp >/dev/null 2>&1 || cd / >/dev/null 2>&1 || true + +supervisorctl_bin="/usr/bin/supervisorctl" +if [[ ! -x "$supervisorctl_bin" ]]; then + supervisorctl_bin="$(command -v supervisorctl 2>/dev/null || true)" +fi +[[ -n "$supervisorctl_bin" ]] || { + printf 'ERROR: supervisorctl not found on the remote host.\n' >&2 + exit 1 +} + +ctl() { + sudo -n "$supervisorctl_bin" "$@" +} + +status_line="$(ctl status "$SSR_PROGRAM" 2>/dev/null || true)" +if ! printf '%s\n' "$status_line" | grep -q "^${SSR_PROGRAM}[[:space:]]"; then + printf 'ERROR: Supervisor program %s not found, or sudo -n supervisorctl is not permitted for this SSH user.\n' "$SSR_PROGRAM" >&2 + ctl status >&2 || true + exit 1 +fi + +ctl restart "$SSR_PROGRAM" + +status="" +i=0 +while [[ "$i" -lt 10 ]]; do + status="$(ctl status "$SSR_PROGRAM" 2>/dev/null | awk '{print $2}' || true)" + if [[ "$status" == "RUNNING" ]]; then + printf ' -> Supervisor program %s is RUNNING\n' "$SSR_PROGRAM" + exit 0 + fi + i=$((i + 1)) + sleep 1 +done + +printf 'ERROR: Supervisor program %s did not reach RUNNING after restart (status: %s).\n' "$SSR_PROGRAM" "${status:-unknown}" >&2 +ctl status "$SSR_PROGRAM" >&2 || true +exit 1 +EOF_SSR_RESTART +} + while [[ $# -gt 0 ]]; do case "$1" in --mode) @@ -1387,8 +1441,6 @@ ssh_remote_app_bash \ COMPOSER_BIN="$(printf '%q' "$composer_bin")" \ RUN_REMOTE_MIGRATIONS="$run_remote_migrations" \ SKIP_MAINTENANCE="$skip_maintenance" \ - SKIP_SSR_RESTART="$skip_ssr_restart" \ - SSR_SUPERVISOR_PROGRAM="$(printf '%q' "$ssr_supervisor_program")" \ DEPLOY_MODE="$(printf '%q' "$deploy_mode")" \ RUN_MEILISEARCH_SETUP="$run_meilisearch_setup" \ FULL_UPGRADE_PRE_HOOK="$(printf '%q' "$full_upgrade_pre_hook")" \ @@ -1913,24 +1965,7 @@ purge_noncurrent_release_runtime_junk() { done < <(find "${REMOTE_RELEASE_ROOT}/releases" -mindepth 1 -maxdepth 1 -type d -print 2>/dev/null || true) } -resolve_ssr_supervisor_target() { - local preferred_program="${SSR_SUPERVISOR_PROGRAM:-skinbase-ssr}" - local detected_program="" - if supervisorctl status "$preferred_program" >/dev/null 2>&1; then - printf '%s' "$preferred_program" - return 0 - fi - - detected_program="$(supervisorctl status 2>/dev/null | awk 'tolower($1) ~ /(ssr|inertia)/ { print $1; exit }')" - - if [[ -n "$detected_program" ]]; then - printf '%s' "$detected_program" - return 0 - fi - - return 1 -} prune_old_releases() { local -a releases=() @@ -2088,35 +2123,6 @@ log_step "Restarting queue workers" log_step "Restarting Horizon workers" "$PHP_BIN" artisan horizon:terminate >/dev/null 2>&1 || true -if [[ "${SKIP_SSR_RESTART:-0}" -eq 0 ]]; then - log_step "Restarting Inertia SSR server" - restart_ssr_with_artisan() { - "$PHP_BIN" artisan inertia:stop-ssr >/dev/null 2>&1 || true - nohup "$PHP_BIN" artisan inertia:start-ssr >/tmp/skinbase-inertia-ssr.log 2>&1 < /dev/null & - } - - if command -v supervisorctl >/dev/null 2>&1; then - ssr_supervisor_target="$(resolve_ssr_supervisor_target || true)" - - if [[ -n "$ssr_supervisor_target" ]]; then - if [[ "$ssr_supervisor_target" != "${SSR_SUPERVISOR_PROGRAM:-skinbase-ssr}" ]]; then - printf ' -> Using detected Supervisor program: %s\n' "$ssr_supervisor_target" - fi - - supervisorctl restart "$ssr_supervisor_target" || { - log_warn "supervisorctl restart ${ssr_supervisor_target} failed — falling back to artisan SSR restart." - restart_ssr_with_artisan || log_warn "artisan SSR restart failed — SSR server may need a manual restart." - } - else - log_warn "Supervisor program '${SSR_SUPERVISOR_PROGRAM:-skinbase-ssr}' not found — falling back to artisan SSR restart. Set SSR_SUPERVISOR_PROGRAM if the server uses a different name." - restart_ssr_with_artisan || log_warn "artisan SSR restart failed — add deploy/supervisor/skinbase-ssr.conf to /etc/supervisor/conf.d/ and run 'supervisorctl reread && supervisorctl update'." - fi - else - log_warn "supervisorctl not available — falling back to artisan SSR restart." - restart_ssr_with_artisan || log_warn "artisan SSR restart failed — SSR server may need a manual restart." - fi -fi - if [[ "$RUN_MEILISEARCH_SETUP" -eq 1 ]]; then if [[ -z "${MEILISEARCH_MODELS_CSV:-}" ]]; then MEILISEARCH_MODELS_CSV='App\Models\Artwork,App\Models\User,App\Models\Group,App\Models\Post,App\Models\Message' @@ -2238,6 +2244,9 @@ if [[ "$remote_deploy_status" -ne 0 ]]; then fi mark_phase_complete "remote-switch" +restart_remote_inertia_ssr +mark_phase_complete "ssr-restart" + # Remote deploy completed successfully; no need for the local DB-maintenance recovery path. db_sync_remote_maintenance=0