Giter Club home page Giter Club logo

wait4x's Introduction

Wait4X

GitHub Workflow Status (branch) Coverage Status Go Report Card Docker Pulls GitHub all releases Packaging status Go Reference

Introduction

Wait4X is a versatile command-line tool designed to wait for various ports or services to reach a specified state. It supports multiple protocols and services, making it an essential tool for CI/CD pipelines, automated testing, and deployment processes.

Features

  • Supports various protocols:
    • TCP
    • HTTP
  • Supports various services:
    • Redis
    • MySQL
    • PostgreSQL
    • InfluxDB
    • MongoDB
    • RabbitMQ
    • Temporal
  • Reverse Checking: Invert the sense of checking to find a free port or non-ready services
  • Parallel Checking: You can define multiple inputs to be checked
  • Exponential Backoff Checking: Retry using an exponential backoff approach to improve efficiency and reduce errors
  • CI/CD Friendly: Well-suited to be part of a CI/CD pipeline step
  • Cross Platform: One single pre-built binary for Linux, Mac OSX, and Windows
  • Importable: Beside the CLI tool, Wait4X can be imported as a pkg in your Go app
  • Command Execution: Execute your desired command after a successful wait

Installation

There are several ways to install Wait4X.

With Docker

Wait4X provides automatically updated Docker images within Docker Hub. It is possible to always use the latest stable tag.

Pull the image from Docker Hub:

docker pull atkrad/wait4x:latest

Then launch the wait4x container:

docker run --rm --name='wait4x' atkrad/wait4x:latest --help

From Binary

Choose the file matching your platform from the release page, then run the following commands:

Linux

curl -#LO https://github.com/atkrad/wait4x/releases/latest/download/wait4x-linux-amd64.tar.gz
tar --one-top-level -xvf wait4x-linux-amd64.tar.gz
sudo cp ./wait4x-linux-amd64/wait4x /usr/local/bin/wait4x

Mac OSX

curl -#LO https://github.com/atkrad/wait4x/releases/latest/download/wait4x-darwin-amd64.tar.gz
tar --one-top-level -xvf wait4x-darwin-amd64.tar.gz
sudo cp ./wait4x-darwin-amd64/wait4x /usr/local/bin/wait4x

Windows

curl -#LO https://github.com/atkrad/wait4x/releases/latest/download/wait4x-windows-amd64.tar.gz
tar --one-top-level -xvf wait4x-windows-amd64.tar.gz

Verify SHA256 Checksum

Wait4X generates checksums for all binaries with sha256sum to prevent against unwanted modification of binaries. To validate the archive files, download the checksum file which ends in .sha256sum for the archive file that you downloaded and use the sha256sum command line tool.

curl -#LO https://github.com/atkrad/wait4x/releases/latest/download/wait4x-linux-amd64.tar.gz.sha256sum
sha256sum --check wait4x-linux-amd64.tar.gz.sha256sum

From Package

You can find the Wait4X package in some Linux distributions.

Packaging status

On Alpine Linux

Wait4X is available in the Alpine Linux community repository.

apk add wait4x

On Arch Linux (AUR)

Wait4X is available in the Arch User Repository (AUR).

yay -S wait4x-bin

On NixOS

Wait4X is available in the NixOS repository.

nix-env -iA nixpkgs.wait4x

On Scoop (Windows)

Wait4X is available in the Scoop bucket.

scoop install wait4x

Examples

TCP

Check TCP connection:

wait4x tcp 127.0.0.1:9090

This command waits until the TCP port 9090 on 127.0.0.1 is available.

HTTP

Check HTTP connection and expect a specific status code:

wait4x http https://ifconfig.co --expect-status-code 200

This command waits until the URL https://ifconfig.co returns an HTTP status code of 200.

Check HTTP connection, status code, and match the response body:

wait4x http https://ifconfig.co/json --expect-status-code 200 --expect-body='"country":\s"Netherlands"'

Check an HTTP response header value:

wait4x http https://ifconfig.co --expect-header "Authorization=Token\s.+"

This command waits until the URL https://ifconfig.co returns an HTTP status code of 200 and the response header matches the provided regex pattern.

Check a body JSON value (value in expected JSON will be processed by gjson):

wait4x http https://ifconfig.co/json --expect-body-json "user_agent.product"

This command waits until the URL https://ifconfig.co/json returns an HTTP status code of 200 and the response body matches the provided GJSON path.

Check body XPath value:

wait4x http https://www.kernel.org/ --expect-body-xpath "//*[@id='tux-gear']"

This command waits until the URL https://www.kernel.org/ returns an HTTP status code of 200 and the response body matches the provided XPath path.

Set request headers:

wait4x http https://ifconfig.co --request-header "Content-Type: application/json" --request-header "Authorization: Token 123"

This command sets the Content-Type and Authorization HTTP request headers and waits until the URL https://ifconfig.co returns an HTTP status code of 200.

Redis

Check Redis connection:

wait4x redis redis://127.0.0.1:6379

This command waits until the Redis server on 127.0.0.1:6379 is ready.

Check Redis connection (with database and credentials):

wait4x redis redis://user:password@localhost:6379/1

This command waits until the Redis server on localhost:6379 is ready to accept connections to the 1 database.

Check Redis connection (Unix socket):

wait4x redis unix://user:password@/path/to/redis.sock?db=1

This command waits until the Redis server on /path/to/redis.sock is ready to accept connections to the 1 database.

Check Redis connection and match a key:

wait4x redis redis://127.0.0.1:6379 --expect-key FOO

This command waits until the Redis server on 127.0.0.1:6379 is ready and the key FOO exists.

Check Redis connection and match a pair of key and value:

wait4x redis redis://127.0.0.1:6379 --expect-key "FOO=^b[A-Z]r$"

This command waits until the Redis server on 127.0.0.1:6379 is ready and the key FOO exists and the value matches the provided regex pattern.

MySQL

Check MySQL connection (TCP):

wait4x mysql 'user:password@tcp(localhost:5555)/dbname'

This command waits until the MySQL server on 127.0.0.1:3306 is ready to accept connections to the dbname database.

Check MySQL connection (Unix socket):

wait4x mysql 'username:password@unix(/tmp/mysql.sock)/myDatabase'

This command waits until the MySQL server on /tmp/mysql.sock is ready to accept connections to the myDatabase database.

Note: Syntax for the database connection string: DSN Data Source Name.

PostgreSQL

Check PostgreSQL connection (TCP):

wait4x postgresql 'postgres://bob:[email protected]:5432/mydatabase?sslmode=disable'

This command waits until the PostgreSQL server on 127.0.0.1:5432 is ready to accept connections to the mydatabase database.

Check PostgreSQL connection (Unix socket):

wait4x postgresql 'postgres://bob:secret@/mydb?host=/var/run/postgresql'

This command waits until the PostgreSQL server on /var/run/postgresql is ready to accept connections to the mydb database.

Note: Syntax for the database DSN: lib/pq.

InfluxDB

Check InfluxDB connection:

wait4x influxdb http://localhost:8086

This command waits until the InfluxDB server on localhost:8086 is ready.

MongoDB

Check MongoDB connection (with credentials and options):

wait4x mongodb 'mongodb://user:[email protected]:27017/?maxPoolSize=20&w=majority'

This command waits until the MongoDB server on 127.0.0.1:27017 is ready.

RabbitMQ

Check RabbitMQ connection (with credentials and vhost):

wait4x rabbitmq 'amqp://guest:[email protected]:5672/vhost'

This command waits until the RabbitMQ server on localhost:5672 is ready.

Temporal

Check Temporal server connection:

wait4x temporal server 127.0.0.1:7233

This command waits until the Temporal server on 127.0.0.1:7233 is ready.

Check insecure Temporal server (no TLS):

wait4x temporal server 127.0.0.1:7233 --insecure-transport

Check a task queue that has registered workers (pollers):

wait4x temporal worker 127.0.0.1:7233 --namespace __YOUR_NAMESPACE__ --task-queue __YOUR_TASK_QUEUE__

This command waits until the Temporal server on 127.0.0.1:7233 is ready and the task queue __YOUR_TASK_QUEUE__ has registered workers (pollers).

#Check a specific Temporal worker (pollers):

wait4x temporal worker 127.0.0.1:7233 --namespace __YOUR_NAMESPACE__ --task-queue __YOUR_TASK_QUEUE__ --expect-worker-identity-regex ".*@__HOSTNAME__@.*"

This command waits until the Temporal server on 127.0.0.1:7233 is ready and the task queue __YOUR_TASK_QUEUE__ has a worker (poller) with an identity matching the provided regex pattern.

Advanced Features

Exponential Backoff

Enable exponential backoff retry:

wait4x http https://ifconfig.co --expect-status-code 200 --backoff-policy exponential --backoff-exponential-max-interval 120s --timeout 120s

This command retries the HTTP connection with exponential backoff until the status code 200 is returned or the timeout of 120s is reached.

Reverse Checking

Check for a free port:

wait4x tcp 127.0.0.1:9090 --reverse

This command waits until the TCP port 9090 on 127.0.0.1 is free.

Parallel Checking

Check multiple services simultaneously:

wait4x tcp 127.0.0.1:9090 127.0.0.1:8080 127.0.0.1:9050

This command waits for the TCP ports 9090, 8080 and 9050 on 127.0.0.1 to be available.

Command Execution

You can execute a command after a successful wait. Use the -- separator to separate the wait4x command from the command to execute.

Example:

wait4x tcp 127.0.0.1:9090 -- echo "Service is up!"

This command will echo "Service is up!" after the TCP port 9090 on 127.0.0.1 is available.

Reporting Issues

If you encounter any issues, please report them here.

Submitting Pull Requests

  1. Fork the repository
  2. Create a new branch (git checkout -b feature-branch)
  3. Make your changes
  4. Commit your changes (git commit -am 'Add new feature')
  5. Push to the branch (git push origin feature-branch)
  6. Create a new Pull Request

License

This project is licensed under the Apache-2.0 license - see the LICENSE file for details.

Copyright 2019-2023 The Wait4X Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

wait4x's People

Contributors

alizdavoodi avatar atkrad avatar dependabot[bot] avatar honwen avatar mortymacs avatar mossroy avatar sbaeurle avatar ykis-0-0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

wait4x's Issues

Incorrect log level for errors when checking resources

The application does not log errors (e.g. incorrect sql password or unreachable host) correctly.

With -l debug the errors are readable, however they should be logged using the error level imo.

Example:

2022-11-14T15:15:39+01:00 INF [PostgreSQL] Checking the [...]:5432 ...
2022-11-14T15:15:39+01:00 DBG pq: Passwort-Authentifizierung für Benutzer postgres fehlgeschlagen
2022-11-14T15:15:40+01:00 INF [PostgreSQL] Checking the [...]:5432 ...
2022-11-14T15:15:40+01:00 DBG pq: Passwort-Authentifizierung für Benutzer postgres fehlgeschlagen
2022-11-14T15:15:41+01:00 INF [PostgreSQL] Checking the [...]:5432 ...
2022-11-14T15:15:41+01:00 DBG pq: Passwort-Authentifizierung für Benutzer postgres fehlgeschlagen

Multiple Address Support Request

What do you think about adding multiple addresses support? For example for HTTP it can be something like this:

wait4x http http://srv1:8080,http://srv2:8080

If both http://srv1:8080 and http://srv2:8080 return the expected result, wait4x exits successfully and otherwise it should be failed.

Maybe we can use comma separated string that is mentioned above or split strings like this:

wait4x http http://srv1:8080  http://srv1:8080

It can help us a lot to improve our deployment process.

Alpine Linux version don't support Command Execution

➜  dockerProjects docker exec -it 265f808d5b08 sh
/ # apk add wait4x
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/x86_64/APKINDEX.tar.gz
(1/1) Installing wait4x (0.4.0-r7)
Executing busybox-1.35.0-r15.trigger
OK: 33 MiB in 43 packages
/ # wait4x version
Version:           v0.4.0
Go version:        go1.18.4
Git commit:        9fcfdc13
Built:             2020-12-21T19:05:13Z
OS/Arch:           linux/amd64
/ # wait4x http http://www.baidu.com http://www.qq.com -- echo "The api is up! Let's use it"
INFO[0000] Checking HTTP connection ...
/ # wait4x http http://www.baidu.com http://www.qq.com -- echo "The api is up! Let's use it"
INFO[0000] Checking HTTP connection ...
/ # wait4x http http://www.baidu.com http://www.qq.com -- echo "The api is up! Let's use it"
INFO[0000] Checking HTTP connection ...
/ # wait4x http http://www.baidu.com http://www.qq.com -- echo "The api is up! Let's use it"
INFO[0000] Checking HTTP connection ...
/ # exit
➜  dockerProjects

--expect-body-json comparison with value

Hi, i am using wait4x in the pipeline using the HTTP provider in order to compare a specific body JSON key with a specific value. AFAIK, also looking at the gjson doc, this seems not possible.
For example a body with

{"version": 1234} 

cannot be done afaik with --expect-body-json with something like:

wait4x http https://ifconfig.co/json --expect-body-json "version==1234" or something similar.

Disable logging

Is it possible to disable logging?

Would be nice to have a --quiet or --slient flag.

Wait indefinitely

The --timeout command-line parameter allows to set a timeout (10s by default).
But I have some cases where I'd like to wait for ever.

Maybe a value of zero could be considered as "for ever"? (It's not the case currently).
Or any other suitable command-line parameter to do that?

Do not reveal passwords in logs

It's the case at least with MySQL and PostgreSQL

When wait4x fails to connect (for example because the DNS name does not yet exist under k8s), it outputs something like:

2023-05-05T23:17:16+02:00 ERR Expectation failed error="failed to establish a connection to the mysql server, caused by: dial tcp: lookup mymariadb on 10.43.0.10:53: no such host" dsn=username:password@tcp(mymariadb:3306)/mydatabase

or

2023-05-06T09:57:46+02:00 ERR Expectation failed error="failed to establish a connection to the postgresql server, caused by: dial tcp 10.43.75.241:5432: connect: connection refused" dsn=postgres://username:password@mypostgres:5432/mydatabase?sslmode=disable

which reveals the password

Ideally, the password would be replaced by stars, or any other means.

Support Context in Checkers

It would great if we can use context instead of pure timeout in checkers but it also needs support from raw connectors.

Adjust pipeline to output .exe for Windows instead of file without extension

If one wants to use Wait4X on Windows or with Windows Containers the current output of the github pipeline cannot be used directly and must be renamed to wait4x.exe to become available in both Powershell and CMD.
Is it possible to change the pipeline output to reflect this requirement already?

PS. If needed I can adjust the stuff myself, just wanted to start a discussion about it first.

Kafka support

It would be great if wait4x was able to test a connection to a Kafka cluster (based on a given bootstrap servers string)

A workaround is to test with tcp, but it's far less precise: the kafka cluster can be up and running even if one of the bootstrap servers is down (for example)

Support POSTing data in http

It would be nice to be able to specify the http request as a POST request with some body.

Something like --with-body '{"foo":"bar"}' could change the verb to POST and behave like the curl -d flag.

Please provide arm images, too

I really like this tool, and use it in Kubernetes initContainers.

But the docker hub images (and release binaries) are only for amd64 architecture.
Would it be possible to provide images for arm architecture, too?

It would allow to use them on RaspberryPi-like devices, and also on Apple M1/M2 CPUs

NATS Support

well if its getting Kafka support then can we have the NATS too :)

HEAD http method support

Hello!

What do you think about supporting head method for http-requests? Now the only GET and POST methods are supported. Sometimes the only thing you want to know is upstream response status code. Upstream page may be hard to GET. With HEAD it will be simpler. Another case is when you only do --expect-header-check is it enough to send HEAD-request.

For example:

# implicit GET http-request:
wait4x http https://ifconfig.co --expect-header "Authorization=Token 1234ABCD"

# explicit HEAD http-request:
wait4x http https://ifconfig.co --expect-header "Authorization=Token 1234ABCD" --http-method head

# explicit HEAD http-request:
wait4x http https://ifconfig.co --expect-status-code 200 --http-method head

All commands work the same, but explicit --http-method head argument sends head-request in some cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.