Skip to content

Instantly share code, notes, and snippets.

@rockotseng
Created May 14, 2018 10:24
Show Gist options
  • Save rockotseng/28fa7fe3244ce9fdcb690231eea1d95b to your computer and use it in GitHub Desktop.
Save rockotseng/28fa7fe3244ce9fdcb690231eea1d95b to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
hostport=(${1//:/ })
host=${hostport[0]}
port=${hostport[1]}
shift
cmd="$@"
if [[ "$host" == "" || "$port" == "" ]]; then
echo "Usage: $0 host:port cmd"
exit 1
fi
while ! nc -z $host $port; do
>&2 echo "Service is unavailable - sleeping"
sleep 1
done
>&2 echo "Service is up - executing command"
exec $cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment