From 9207daa433d4c1ebed3a3ea2df3980f3491cd396 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 27 Jul 2026 03:00:30 +0000 Subject: [PATCH] Stop the old sms-inbound instance before a fresh reinstall, not after MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The port-taken message on the last run ("Port 8093 was taken — the relay will use 8094") was this service colliding with itself, not a real conflict. Fresh-install never stopped the previous run before scanning for a free port, so it always found its own earlier process still bound to 8093, silently moved to 8094, and then `systemctl enable --now` was a no-op against an already-active unit -- meaning the OLD process (holding the OLD AMI secret and OLD relay token, from before this session's settings.env fix) kept serving traffic while the freshly-written config and port sat unused underneath it. Fix: `systemctl stop sms-inbound` right before the port scan. Now the scan only reports a real conflict from something else, and the box should settle back on 8093 (or whatever's actually free) with the process that's really running matching what was just configured. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01JDyKC6Kdg7tofmYSmRtgww --- services/sms-inbound.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/sms-inbound.sh b/services/sms-inbound.sh index 903f276..7f1001d 100644 --- a/services/sms-inbound.sh +++ b/services/sms-inbound.sh @@ -732,12 +732,21 @@ install_sms-inbound() { # ── Relay service ───────────────────────────────────────────────────────── mkdir -p "$SMS_APP_DIR" + # Stop any instance of this exact service BEFORE scanning for a free + # port. Otherwise a fresh install run while the service is still up + # from a previous run always finds its own old process squatting on + # 8093, "frees" itself onto 8094 instead, and `enable --now` below is + # then a no-op against an already-active unit — leaving the OLD + # process (old token, old AMI secret) as the one actually serving + # traffic while the newly-written config sits unused. Confirmed live: + # exactly this sequence on a re-run right after a fresh install. + systemctl stop sms-inbound 2>/dev/null || true local RELAY_PORT=8093 local _limit=$((RELAY_PORT + 100)) while ss -tlnH "sport = :${RELAY_PORT}" 2>/dev/null | grep -q . && [[ "$RELAY_PORT" -lt "$_limit" ]]; do RELAY_PORT=$((RELAY_PORT + 1)) done - [[ "$RELAY_PORT" != 8093 ]] && log_info "Port 8093 was taken — the relay will use ${RELAY_PORT}." + [[ "$RELAY_PORT" != 8093 ]] && log_info "Port 8093 was taken by something else — the relay will use ${RELAY_PORT}." local RELAY_TOKEN RELAY_TOKEN="$(generate_password 32)"