Skip to content

Instantly share code, notes, and snippets.

@zzak
Created March 1, 2023 22:33
Show Gist options
  • Save zzak/5e0a9a177145db4f0969f0136318681d to your computer and use it in GitHub Desktop.
Save zzak/5e0a9a177145db4f0969f0136318681d 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