项目作者: clarketm

项目描述 :
Wait for service(s) to be available before executing a command.
高级语言: Python
项目地址: git://github.com/clarketm/wait-for-it.git
创建时间: 2018-10-01T07:29:59Z
项目社区:https://github.com/clarketm/wait-for-it

开源协议:MIT License

下载


[!IMPORTANT]
The wait-for-it project has a new home at https://github.com/hartwork/wait-for-it by now.

wait-for-it

PyPi release
PyPi versions
Downloads
Documentation Status

Wait for service(s) to be available before executing a command.





wait-for-it is a script that will wait on the availability of one or more TCP services (i.e. host:port) before executing a user-defined command.
It is useful for synchronizing the spin-up of interdependent services, such as linked docker containers.

Since v2.0.0, wait-for-it will return the exit code of the executed command(s).

Check out the wait-for-it docs

Installation

  1. $ pip install wait-for-it

Demo

usage demo

Usage

  1. Usage: wait-for-it [OPTIONS] [COMMANDS]...
  2. Wait for service(s) to be available before executing a command.
  3. Options:
  4. -h, --help Show this message and exit.
  5. -v, --version Show the version and exit.
  6. -q, --quiet Do not output any status messages
  7. -p, --parallel Test services in parallel rather than in serial
  8. -t, --timeout seconds Timeout in seconds, 0 for no timeout [default: 15]
  9. -s, --service host:port Services to test, in one of the formats: ':port',
  10. 'hostname:port', 'v4addr:port', '[v6addr]:port' or
  11. 'https://...'

Examples

Test to see if we can access port 80 on www.google.com, and if it is available, echo the message google is up:

  1. $ wait-for-it \
  2. --service www.google.com:80 \
  3. -- echo "google is up"
  1. [*] Waiting 15 seconds for www.google.com:80
  2. [+] www.google.com:80 is available after 0 seconds
  3. 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:

  1. $ wait-for-it \
  2. --service www.google.com:80 \
  3. --timeout 0 \
  4. -- echo "google is up"
  1. [*] Waiting for www.google.com:80 without a timeout
  2. [+] www.google.com:80 is available after 0 seconds
  3. google is up

Multiple services can be tested by adding additional -s or --service options:

  1. $ wait-for-it \
  2. --service www.google.com:80 \
  3. --service www.bing.com:80 \
  4. --service www.duckduckgo.com:80 \
  5. -- echo "google, bing, and duckduckgo are up"
  1. [*] Waiting 15 seconds for www.google.com:80
  2. [+] www.google.com:80 is available after 0 seconds
  3. [*] Waiting 15 seconds for www.bing.com:80
  4. [+] www.bing.com:80 is available after 0 seconds
  5. [*] Waiting 15 seconds for www.duckduckgo.com:80
  6. [+] www.duckduckgo.com:80 is available after 0 seconds
  7. google, bing, and duckduckgo are up

By adding the -p or --parallel option, wait-for-it can do the same in parallel rather than serial:

  1. $ wait-for-it \
  2. --parallel \
  3. --service www.google.com:80 \
  4. --service www.bing.com:80 \
  5. --service www.duckduckgo.com:80 \
  6. -- echo "google, bing, and duckduckgo are up"
  1. [*] Waiting 15 seconds for www.bing.com:80
  2. [*] Waiting 15 seconds for www.duckduckgo.com:80
  3. [*] Waiting 15 seconds for www.google.com:80
  4. [+] www.bing.com:80 is available after 0 seconds
  5. [+] www.duckduckgo.com:80 is available after 0 seconds
  6. [+] www.google.com:80 is available after 0 seconds
  7. google, bing, and duckduckgo are up

Status message output can be suppressed with the -q or --quiet option:

  1. $ wait-for-it \
  2. --quiet \
  3. --service www.google.com:80 \
  4. -- echo "google is up"
  1. google is up

License

MIT © Travis Clarke,
Sebastian Pipping