Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,5 @@ writeShellApplication {
# beware: the first result on nixos search, netcat-gnu, is outdated and
# broken.
runtimeInputs = [ netcat ];
text = ''
if [[ $# -eq 0 ]] ; then
nc
exit 1
fi
until nc -z localhost "$@"; do sleep 1; done
'';
text = builtins.readFile ./wait-for-port.sh;
}
25 changes: 25 additions & 0 deletions packages/wait-for-port/wait-for-port.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -euo pipefail

while getopts "t:" opt; do
case "$opt" in
t)
DEADLINE="$((EPOCHSECONDS + OPTARG))"
shift
shift
;;
"?")
>&2 echo "Invalid option"
exit 1
;;
esac
done

until nc -z localhost "$@"; do
if [[ -n "${DEADLINE-}" && "$DEADLINE" -le "$EPOCHSECONDS" ]]; then
>&2 echo "Timeout"
exit 1
fi
sleep 1
done