Command-line tool and Go library to wait for conditions

go get


Build Status Coverage Status


Command-line tool and Go library to wait for various conditions to become true. Inspired by Ansible's wait_for module. It currently supports port checks. More checks will be added in the future, e.g. checks for files, processes.


Make sure Go is installed and setup correctly. To pull the library into the $GOPATH directory, build the binary, and put it into the $GOBIN directory, simply run:

go get

Assuming your $PATH contains $GOBIN, you can now run waitfor from anywhere on your machine.

waitfor --help

Command-line Interface

Wait for Host to Listen on Port

$ waitfor port --help
   waitfor port - wait for host to listen on port

   waitfor port [command options] [arguments...]

   --closed, -c         wait for port to be closed
   --host, -h ""   resolvable hostname or IP address
   --network, -n "tcp"      named network, ['tcp', 'tcp4', 'tcp6', 'udp', 'udp4', 'udp6', 'ip', 'ip4', 'ip6']
   --timeout, -t "5m0s"     maximum time to wait for
   --interval, -i "1s"      time in-between checks
   --verbose, -v        enable additional logging

For example, wait up to 1 minute for localhost to listen on port 8080 using the tcp protocol. Check port every 500 milliseconds.

waitfor port 8080 -h localhost -n tcp -t 1m -i 500ms

Wait for Host to Stop Listening on Port

Use the --closed flag to wait for a port to be closed.

waitfor port 8080 -h localhost -n tcp -c