@@ -1930,12 +1930,20 @@ if [[ "$MODE" == "0" ]] || [[ "$MODE" == "pg" ]]; then
19301930 echo_log " "
19311931 echo_log " ✅ Postgres connectivity verified ---"
19321932 # Check lsof is available before attempting to use it
1933- echo_log " TEST1"
1934- if ! command -v lsof & > /dev/null; then
1935- echo_log " ERROR: 'lsof' is not installed or not in PATH"
1933+ debug_log " TEST1"
1934+ if command -v ss & > /dev/null; then
1935+ debug_log " using ss to detect PG API Port"
1936+ PG_API_PORT=$( ss -tlnp | awk ' /postgres/ && $4 !~ /:5432$/ {split($4, a, ":"); print a[length(a)]; exit}' )
1937+ elif ! command -v lsof & > /dev/null; then
1938+ debug_log " using lsof to detect PG API Port"
1939+ PG_API_PORT=$( lsof -i -P | awk ' /postgres/ && /LISTEN/ && $9 ~ /localhost/ && $9 !~ /5432/ {split($9, a, ":"); ports[++count] = a[2]} END {if (count >= 2) print ports[2]}' )
1940+ elif command -v netstat & > /dev/null; then
1941+ debug_log " WARNING: i'ss' and 'lsof' not found, falling back to 'netstat'"
1942+ PG_API_PORT=$( netstat -tlnp 2> /dev/null | awk ' /postgres/ && $4 !~ /:5432$/ {split($4, a, ":"); print a[length(a)]; exit}' )
1943+ else
1944+ warn_log " ERROR: None of 'lsof', 'ss', or 'netstat' are available"
19361945 fi
1937- PG_API_PORT=$( lsof -i -P | awk ' /postgres/ && /LISTEN/ && $9 ~ /localhost/ && $9 !~ /5432/ {split($9, a, ":"); ports[++count] = a[2]} END {if (count >= 2) print ports[2]}' )
1938- echo_log " TEST"
1946+ debug_log " TEST"
19391947 if [ -z " $PG_API_PORT " ]; then
19401948 debug_log " ERROR: Could not determine PostgreSQL API port"
19411949 else
0 commit comments