Check all published ports before deployment

This commit is contained in:
AlexChard
2026-08-29 19:24:53 +04:00
parent d97726aa91
commit 2b373661d6
2 changed files with 10 additions and 5 deletions
+8 -3
View File
@@ -90,17 +90,22 @@ command -v ss >/dev/null 2>&1 || die "The 'ss' utility is required (package: ipr
command -v curl >/dev/null 2>&1 || die "The 'curl' utility is required. Nothing was changed."
command -v getent >/dev/null 2>&1 || die "The 'getent' utility is required (package: libc-bin). Nothing was changed."
port_busy() { ss -H -ltn "sport = :$1" 2>/dev/null | grep -q .; }
tcp_port_busy() { ss -H -ltn "sport = :$1" 2>/dev/null | grep -q .; }
udp_port_busy() { ss -H -lun "sport = :$1" 2>/dev/null | grep -q .; }
our_stack_running() {
command -v docker >/dev/null 2>&1 &&
docker ps --filter "label=com.docker.compose.project=$PROJECT_NAME" --format '{{.ID}}' | grep -q .
}
for port in 80 443; do
if port_busy "$port" && ! our_stack_running; then
for port in 80 443 3000; do
if tcp_port_busy "$port" && ! our_stack_running; then
ss -ltnp "sport = :$port" >&2 || true
die "TCP port $port is already occupied by another service. Nothing was changed. Integrate with the existing reverse proxy instead of forcing takeover."
fi
done
if udp_port_busy 443 && ! our_stack_running; then
ss -lunp 'sport = :443' >&2 || true
die "UDP port 443 is already occupied by another service. Nothing was changed."
fi
PUBLIC_IP="$(curl -4fsS --max-time 6 https://api.ipify.org 2>/dev/null || true)"
for domain in "$DOH_DOMAIN" "$ADMIN_DOMAIN"; do