waitfor

Overview

This utility will wait until a url is available, until a port is being listened to, until an amount of time has passed or until a shell command succeeds. It's very useful when you want to coordinate the startup or shutdown of services. Each item you wish to wait for is specified on the command line as a series of URLs. The program will repeatedly test each one until it 'succeeds' or until the maximum wait time is exceeded.

You specify the resources you're waiting for as URLs such as:
Prefix any test with '!' to wait for it to fail instead.

Invoked with the -? option, the program prints a usage summary and exits.
The -p option allows you to set how frequently the program should attempt to check the tests. The default is 1 second.
The -w option allows you to set how long the program will wait for the tests to succeed (before exiting with a 1 error code). The default is to wait forever.
The -v option will log all tests as they're being executed. It's mainly useful for debugging.

Install

The easiest way is to simply use the RPM version. However, if you prefer to do it yourself (or have an non-RPM linux distribution) just copy the waitfor file to /usr/bin.

Examples

To check is Tomcat running and exit immediately (with a return code of 0 if it is and 1 if it isn't)
waitfor -w0 port:8080
To shutdown Tomcat and wait until it stops:
$TOMCAT/bin/shutdown.sh
waitfor '!port:8080'
To wait until a web server has fully started:
waitfor http://localhost/index.html

Download

Source: waitfor-0.5.tar.gz
RPM: waitfor-0.5-1.noarch.rpm