Skip to content

Instantly share code, notes, and snippets.

@jkutner
Last active January 27, 2018 14:47
Show Gist options
  • Save jkutner/2912686d514c37189cb49b71c6e7333a to your computer and use it in GitHub Desktop.
Save jkutner/2912686d514c37189cb49b71c6e7333a to your computer and use it in GitHub Desktop.
#! /bin/bash
BOOT_TIMEOUT=55
forward_wrong_port() {
sleep $BOOT_TIMEOUT
local ports="$(ss -lt | awk '/LISTEN/ { print $4 }' | grep "*:[0-9]*")"
if echo "$ports" | grep -v "*:$PORT$"; then
local user_port="$(echo "$ports" | sed 's/\*://' | head -n 1)"
socat TCP-LISTEN:$PORT,fork TCP:0.0.0.0:$user_port
fi
}
forward_wrong_port &
#! /bin/bash
BOOT_TIMEOUT=60
warn_wrong_port() {
local end=$((SECONDS+BOOT_TIMEOUT))
while [ $SECONDS -lt $end ]; do
local ports="$(ss -lt | awk '/LISTEN/ { print $4 }' | grep "*:[0-9]*" | sed 's/\*://')"
for port in $ports; do
if [ "$port" != "$PORT" ]; then
echo "WARNING: Your app is binding to $port instead of the value defined by the \$PORT environment variable. You may recevie an R10 error."
fi
done
sleep 10
done
}
warn_wrong_port &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment