For example, let's test to see if we can access port 80 on www.google.com, and if it is available, echo the message `google is up`.
[source, sh]
...
...
@@ -42,20 +45,7 @@ wait-for-it.sh: www.google.com:80 is available after 0 seconds
google is up
----
The subcommand will be executed regardless if the service is up or not.
If you wish to execute the subcommand only if the service is up, add the `--strict` argument.
In this example, we will test port 81 on www.google.com which will fail:
[source, sh]
----
$ ./wait-for-it.sh www.google.com:81 --timeout=1 --strict -- echo "google is up"
wait-for-it.sh: waiting 1 seconds for www.google.com:81
wait-for-it.sh: timeout occurred after waiting 1 seconds for www.google.com:81
wait-for-it.sh: strict mode, refusing to execute subprocess
----
If you don't want to execute a subcommand, leave off the `--` argument.
This way, you can test the exit condition of `wait-for-it.sh` in your own scripts, and determine how to proceed:
You can test the exit condition of `wait-for-it.sh` in your own scripts, and determine how to proceed:
[source, sh]
----
...
...
@@ -71,6 +61,37 @@ $ echo $?
124
----
== Community
=== Subcommands
A subcommand will be executed regardless of whether the service is up or not.
If you wish to execute the subcommand only if the service is up, add the `--strict` argument.
In this example, we will test port 81 on www.google.com which will fail:
_Debian_: There is a https://tracker.debian.org/pkg/wait-for-it[Debian package].
[source, sh]
----
$ ./wait-for-it.sh www.google.com:81 --timeout=1 --strict -- echo "google is up"
wait-for-it.sh: waiting 1 seconds for www.google.com:81
wait-for-it.sh: timeout occurred after waiting 1 seconds for www.google.com:81
wait-for-it.sh: strict mode, refusing to execute subprocess
----
=== Docker
[NOTE]
====
Take care when using this utility to test for a running service within a docker container. When Docker is starting up a container, the ports will become available ver early even if the backing service is not running already! To account for this behavior you need to do some sort of communication with the backend to ensure it is up and running.