• Stars
    star
    9,300
  • Rank 3,852 (Top 0.08 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pure bash script to test and wait on the availability of a TCP host and port

wait-for-it

wait-for-it.sh is a pure bash script that will wait on the availability of a host and TCP port. It is useful for synchronizing the spin-up of interdependent services, such as linked docker containers. Since it is a pure bash script, it does not have any external dependencies.

Usage

wait-for-it.sh host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST       Host or IP under test
-p PORT | --port=PORT       TCP port under test
                            Alternatively, you specify the host and port as host:port
-s | --strict               Only execute subcommand if the test succeeds
-q | --quiet                Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
                            Timeout in seconds, zero for no timeout
-- COMMAND ARGS             Execute command with args after the test finishes

Examples

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.

$ ./wait-for-it.sh www.google.com:80 -- echo "google is up"
wait-for-it.sh: waiting 15 seconds for www.google.com:80
wait-for-it.sh: www.google.com:80 is available after 0 seconds
google is up

You can set your own timeout with the -t or --timeout= option. Setting the timeout value to 0 will disable the timeout:

$ ./wait-for-it.sh -t 0 www.google.com:80 -- echo "google is up"
wait-for-it.sh: waiting for www.google.com:80 without a timeout
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:

$ ./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:

$ ./wait-for-it.sh www.google.com:80
wait-for-it.sh: waiting 15 seconds for www.google.com:80
wait-for-it.sh: www.google.com:80 is available after 0 seconds
$ echo $?
0
$ ./wait-for-it.sh www.google.com:81
wait-for-it.sh: waiting 15 seconds for www.google.com:81
wait-for-it.sh: timeout occurred after waiting 15 seconds for www.google.com:81
$ echo $?
124

Community

Debian: There is a Debian package.

More Repositories

1

python-midi

Python MIDI library
C
1,457
star
2

snowflake

Snowflake Generator
Python
103
star
3

silhouette

Open-source python library to drive the Silhouette cutter
Python
82
star
4

kinet

Python API to control Color Kinetics lights using kinet
Python
39
star
5

ssw

Python interface for SIMD Smith-Waterman Library
C
36
star
6

rockit

Model Rocket Construction Kit
Python
27
star
7

octocmd

Command line interface for OctoPrint
Python
11
star
8

penetrails

Explorations in Machine Learning
Python
11
star
9

bigdripper

The bigdripper is an installation piece for Collision Collective 16.
Java
11
star
10

pyscad

Python SCAD Interface
Python
9
star
11

allegro

Allegro A6281 LED API
Python
7
star
12

3dobj

3D Objects
OpenSCAD
4
star
13

pixace

Image Transformer
Python
4
star
14

cricetinae

Repository for the Human Music Wheel
Shell
4
star
15

harmonograph

Python toy to generate harmonographs
Python
3
star
16

pycon2016

Supplemental information for Pycon 2016 talk.
CSS
3
star
17

armi

Framework for Arduino+MIDI
C
3
star
18

WS2801

WS2801
C++
3
star
19

cairo

Fork of git://git.cairographics.org/git/cairo
C
3
star
20

hdpov

Hard Drive Persistence of Vision
Java
2
star
21

wub

Python audio analysis toolkit
C++
2
star
22

lampy

Lambdamoo for Python
2
star
23

image-caption

Simple python script to add a caption to an image
Python
2
star
24

mythonic

Sonic Storyboard Repo
C++
2
star
25

strobe

Arduino Strobe Driver
C++
2
star
26

photobooth

JavaScript
2
star
27

gearbox

Gearbox: Helpful tools for the young computational professional on the go.
Python
1
star
28

kairos

Kairos is a project exploring sequenced high speed photography
Python
1
star
29

infosys

InfoSys, a vt200 media system
Python
1
star
30

sketchbook

Processing Sketchbook
Java
1
star
31

speedphoto

Java
1
star
32

tilebot

Code for Tile Bot
C
1
star
33

bones

Bones, a python toolkit for biology
Python
1
star
34

sabot

Python extension classes for Boto3
Python
1
star
35

HL1606

Collection of HL1606 libraries and projects
C++
1
star
36

kidmx

Raspberry Pi kinet ethernet to DMX bridge
C++
1
star