Skip to content

Instantly share code, notes, and snippets.

@henri
Forked from zzak/await.sh
Created July 16, 2025 02:14
Show Gist options
  • Save henri/3a25aa3e3519863b27dc4e14dd27efee to your computer and use it in GitHub Desktop.
Save henri/3a25aa3e3519863b27dc4e14dd27efee to your computer and use it in GitHub Desktop.
Script to wait for localhost service in bash, with retries
#!/usr/bin/env bash
set -euo pipefail
TRIES=0
until [ $TRIES -eq 10 ] || nc -z localhost 3000; do
sleep 0.1
TRIES=$(( TRIES+1 ))
done
if [[ $TRIES -gt 9 ]]
then
echo "Failed to connect to container..."
exit 999
else
echo "Container started!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment