Skip to main content

Wait until TCP endpoints are open

Project description

tcpw

tcpw (TCP Wait) is a tool that waits until TCP endpoints are open.

It is useful for synchronizing the spin-up of interdependent services, such as linked docker containers.

That is yet another alternative to wait-for-it.sh.

Rationale

  • available as a binary executable without any dependencies (file size <1mb).
  • available on PyPI
  • additionally, you can set:
    • more than one endpoint: -a google.com:80 -a booble.gum:8080 ...
    • command, which can be executed only after success, failure or any result: -on f -a google.com:9999 echo "Endpoint is down"
    • polling interval: -i 500ms
    • timeout/interval in different time units: ns,ms,s,m,h

Installation

Download executable file:

sh -c "wget -O tcpw https://raw.githubusercontent.com/jackcvr/tcpw/main/tcpw/tcpw-$(uname -m) && chmod +x tcpw"

or:

pip install tcpw

PyPI - Version PyPI - Python Version

Usage

Usage: tcpw [-t timeout] [-i interval] [-on (s|f|any)] [-q] [-v] [-a host:port ...] [command [args]]

  -a value
    	Endpoint to await, in the form 'host:port'
  -i duration
    	Interval between retries in format N{ns,ms,s,m,h} (default 1s)
  -on string
    	Condition for command execution. Possible values: 's' - after success, 'f' - after failure, 'any' - always (default 's') (default "s")
  -q	Do not print anything (default false)
  -t duration
    	Timeout in format N{ns,ms,s,m,h}, e.g. '5s' == 5 seconds. Zero for no timeout (default 0)
  -v	Verbose mode (default false)
  command args
    	Execute command with arguments after the test finishes (default: if connection succeeded)

Examples

Wait 5 seconds for port 80 on www.google.com, and if it is available, echo the message Google is up:

$ tcpw -t 5s -a www.google.com:80 echo "Google is up"
2024/08/26 20:06:47.209012 successfully connected to www.google.com:80
Google is up

Next command waits 2 seconds for www.google.com:80 and localhost:5000, checking them every 500 milliseconds with enabled verbose mode and executes echo regardless of the result:

$ tcpw -t 2s -i 500ms -v -on any -a www.google.com:80 -a localhost:5000 echo "Printed anyway"
2024/08/26 20:08:24.153240 connecting to localhost:5000...
2024/08/26 20:08:24.153327 connecting to www.google.com:80...
2024/08/26 20:08:24.153541 dial tcp 127.0.0.1:5000: connect: connection refused
2024/08/26 20:08:24.179927 successfully connected to www.google.com:80
2024/08/26 20:08:24.654984 dial tcp 127.0.0.1:5000: connect: connection refused
2024/08/26 20:08:25.155997 dial tcp 127.0.0.1:5000: connect: connection refused
2024/08/26 20:08:25.661397 dial tcp 127.0.0.1:5000: connect: connection refused
2024/08/26 20:08:26.161613 dial tcp: lookup localhost: i/o timeout
timeout error
Printed anyway

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tcpw-0.1.3.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

tcpw-0.1.3-py3-none-any.whl (2.5 MB view details)

Uploaded Python 3

File details

Details for the file tcpw-0.1.3.tar.gz.

File metadata

  • Download URL: tcpw-0.1.3.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for tcpw-0.1.3.tar.gz
Algorithm Hash digest
SHA256 cffe06319b6facbc9f5e9bd43c1890028c9b8ee0a4d69c293fc62479a0545d0f
MD5 2a9a9bb9bf4b448902de3d48e314d7d4
BLAKE2b-256 bb4adfb84e53579a4284cab8bfc18c7825a85425c7e247c2c4bda76e5260c827

See more details on using hashes here.

File details

Details for the file tcpw-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: tcpw-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for tcpw-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 841546be1f7e3308446212e71ac61f86b81202ee386897a7635864d7c10e6151
MD5 71b0f8d1420773afcd1134a5d1f9015a
BLAKE2b-256 d09872572e62a57b1120d94197c0d260a255d6a59af2ce4dddde023d690f7335

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page