Skip to content

Instantly share code, notes, and snippets.

@shahidhk
Last active August 29, 2018 10:11
Show Gist options
  • Save shahidhk/2259907bcbc5bc8c6f23d8021cdedfa0 to your computer and use it in GitHub Desktop.
Save shahidhk/2259907bcbc5bc8c6f23d8021cdedfa0 to your computer and use it in GitHub Desktop.

Revisions

  1. shahidhk revised this gist Aug 29, 2018. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions wait-for-port-nc.bash
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #!/usr/bin/env bash

    # wait for a program to start listening on a PORT ($1)
    wait_for_port() {
    local PORT=$1
    echo "waiting for $PORT"
    @@ -10,7 +11,4 @@ wait_for_port() {
    sleep 1
    done
    echo "Failed waiting for $PORT" && exit 1
    }

    # wait for port 5432
    wait_for_port 5432
    }
  2. shahidhk created this gist Aug 29, 2018.
    16 changes: 16 additions & 0 deletions wait-for-port-nc.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/usr/bin/env bash

    wait_for_port() {
    local PORT=$1
    echo "waiting for $PORT"
    for i in `seq 1 60`;
    do
    nc -z localhost $PORT && echo "port $PORT is ready" && return
    echo -n .
    sleep 1
    done
    echo "Failed waiting for $PORT" && exit 1
    }

    # wait for port 5432
    wait_for_port 5432