π Table of Contents
π Overview
Wait4X is a powerful, zero-dependency tool that waits for services to be ready before continuing. It supports multiple protocols and services, making it an essential component for:
- CI/CD pipelines - Ensure dependencies are available before tests run
- Container orchestration - Health checking services before application startup
- Deployment processes - Verify system readiness before deploying
- Application initialization - Validate external service availability
- Local development - Simplify localhost service readiness checks
β¨ Features
Multi-Protocol Support | TCP, HTTP, DNS |
Service Integrations | Redis, MySQL, PostgreSQL, MongoDB, RabbitMQ, InfluxDB, Temporal |
Reverse Checking | Invert checks to find free ports or non-ready services |
Parallel Checking | Check multiple services simultaneously |
Exponential Backoff | Retry with increasing delays to improve reliability |
CI/CD Integration | Designed for automation workflows |
Cross-Platform | Single binary for Linux, macOS, and Windows |
Go Package | Import into your Go applications |
Command Execution | Run commands after successful checks |
π₯ Installation
π³ With Docker
Wait4X provides automatically updated Docker images within Docker Hub:
docker pull wait4x/wait4x:latest
docker run --rm wait4x/wait4x:latest --help
π¦ From Binary
Download the appropriate version for your platform from the releases page:
Linux:
curl -LO https://github.com/wait4x/wait4x/releases/latest/download/wait4x-linux-amd64.tar.gz
tar -xf wait4x-linux-amd64.tar.gz -C /tmp
sudo mv /tmp/wait4x-linux-amd64/wait4x /usr/local/bin/
macOS:
curl -LO https://github.com/wait4x/wait4x/releases/latest/download/wait4x-darwin-amd64.tar.gz
tar -xf wait4x-darwin-amd64.tar.gz -C /tmp
sudo mv /tmp/wait4x-darwin-amd64/wait4x /usr/local/bin/
Windows:
curl -LO https://github.com/wait4x/wait4x/releases/latest/download/wait4x-windows-amd64.tar.gz
tar -xf wait4x-windows-amd64.tar.gz
Verify checksums:
curl -LO https://github.com/wait4x/wait4x/releases/latest/download/wait4x-linux-amd64.tar.gz.sha256sum
sha256sum --check wait4x-linux-amd64.tar.gz.sha256sum
π¦ From Package Managers
Alpine Linux:
apk add wait4x
Arch Linux (AUR):
yay -S wait4x-bin
NixOS:
nix-env -iA nixpkgs.wait4x
Windows (Scoop):
scoop install wait4x

π Quick Start
Basic TCP Check
Wait for a port to become available:
wait4x tcp localhost:3306
HTTP Health Check
Wait for a web server with specific response:
wait4x http https://example.com/health --expect-status-code 200 --expect-body-regex '"status":"UP"'
Multi-Service Check (Parallel)
Wait for multiple services simultaneously:
wait4x tcp 127.0.0.1:5432 127.0.0.1:6379 127.0.0.1:27017
Database Readiness
Wait for PostgreSQL to be ready:
wait4x postgresql 'postgres://user:pass@localhost:5432/mydb?sslmode=disable'
Execute After Success
Run a command after services are ready:
wait4x tcp localhost:8080 -- echo "Service is ready!" && ./start-app.sh
π Detailed Usage
π HTTP Checking
Checking with Status Code
Wait for an HTTP endpoint to return a specific status code:
wait4x http https://api.example.com/health --expect-status-code 200
Checking Response Body with Regex
Wait for an HTTP endpoint to return a response that matches a regex pattern:
wait4x http https://api.example.com/status --expect-body-regex '"status":\s*"healthy"'
Checking Response Body with JSON Path
Wait for a specific JSON field to exist or have a specific value:
wait4x http https://api.example.com/status --expect-body-json "services.database.status"
This uses GJSON Path Syntax for powerful JSON querying.
Checking Response Body with XPath
Wait for an HTML/XML response to match an XPath query:
wait4x http https://example.com --expect-body-xpath "//div[@id='status']"
Send specific headers with your HTTP request:
wait4x http https://api.example.com \
--request-header "Authorization: Bearer token123" \
--request-header "Content-Type: application/json"
Wait for a response header to match a pattern:
wait4x http https://api.example.com --expect-header "Content-Type=application/json"
π DNS Checking
Check A Records
wait4x dns A example.com
wait4x dns A example.com --expected-ip 93.184.216.34
wait4x dns A example.com --expected-ip 93.184.216.34 -n 8.8.8.8
Check AAAA Records (IPv6)
wait4x dns AAAA example.com --expected-ip "2606:2800:220:1:248:1893:25c8:1946"
Check CNAME Records
wait4x dns CNAME www.example.com --expected-domain example.com
Check MX Records
wait4x dns MX example.com --expected-domain "mail.example.com"
Check NS Records
wait4x dns NS example.com --expected-nameserver "ns1.example.com"
Check TXT Records
wait4x dns TXT example.com --expected-value "v=spf1 include:_spf.example.com ~all"
πΎ Database Checking
MySQL
wait4x mysql 'user:password@tcp(localhost:3306)/mydb'
wait4x mysql 'user:password@unix(/var/run/mysqld/mysqld.sock)/mydb'
PostgreSQL
wait4x postgresql 'postgres://user:password@localhost:5432/mydb?sslmode=disable'
wait4x postgresql 'postgres://user:password@/mydb?host=/var/run/postgresql'
MongoDB
wait4x mongodb 'mongodb://user:password@localhost:27017/mydb?maxPoolSize=20'
Redis
wait4x redis redis://localhost:6379
wait4x redis redis://user:password@localhost:6379/0
wait4x redis redis://localhost:6379 --expect-key "session:active"
wait4x redis redis://localhost:6379 --expect-key "status=^ready$"
InfluxDB
wait4x influxdb http://localhost:8086
π Message Queue Checking
RabbitMQ
wait4x rabbitmq 'amqp://guest:guest@localhost:5672/myvhost'
Temporal
wait4x temporal server localhost:7233
wait4x temporal worker localhost:7233 \
--namespace my-namespace \
--task-queue my-queue
wait4x temporal worker localhost:7233 \
--namespace my-namespace \
--task-queue my-queue \
--expect-worker-identity-regex "worker-.*"
βοΈ Advanced Features
β±οΈ Timeout & Retry Control
Setting Timeout
Limit the total time Wait4X will wait:
wait4x tcp localhost:8080 --timeout 30s
Setting Interval
Control how frequently Wait4X retries:
wait4x tcp localhost:8080 --interval 2s
Exponential Backoff
Use exponential backoff for more efficient retries:
wait4x http https://api.example.com \
--backoff-policy exponential \
--backoff-exponential-coefficient 2.0 \
--backoff-exponential-max-interval 30s
βοΈ Reverse Checking
Wait for a port to become free:
wait4x tcp localhost:8080 --invert-check
Wait for a service to stop:
wait4x http https://service.local/health --expect-status-code 200 --invert-check
β‘ Command Execution
Execute commands after successful wait:
wait4x tcp localhost:3306 -- ./deploy.sh
Chain multiple commands:
wait4x redis redis://localhost:6379 -- echo "Redis is ready" && ./init-redis.sh
π Parallel Checking
Wait for multiple services simultaneously:
wait4x tcp localhost:3306 localhost:6379 localhost:27017
Note that this waits for ALL specified services to be ready.
π¦ Go Package Usage
π Installing as a Go Package
Add Wait4X to your Go project:
go get wait4x.dev/v3
Import the packages you need:
import (
"context"
"time"
"wait4x.dev/v3/checker/tcp"
"wait4x.dev/v3/checker/http"
"wait4x.dev/v3/checker/redis"
"wait4x.dev/v3/waiter"
)
π Example: TCP Checking
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
tcpChecker := tcp.New("localhost:6379", tcp.WithTimeout(5*time.Second))
err := waiter.WaitContext(
ctx,
tcpChecker,
waiter.WithTimeout(time.Minute),
waiter.WithInterval(2*time.Second),
waiter.WithBackoffPolicy("exponential"),
)
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
fmt.Println("Service is ready!")
π Example: HTTP with Advanced Options
headers := http.Header{}
headers.Add("Authorization", "Bearer token123")
headers.Add("Content-Type", "application/json")
checker := http.New(
"https://api.example.com/health",
http.WithTimeout(5*time.Second),
http.WithExpectStatusCode(200),
http.WithExpectBodyJSON("status"),
http.WithExpectBodyRegex(`"healthy":\s*true`),
http.WithExpectHeader("Content-Type=application/json"),
http.WithRequestHeaders(headers),
)
err := waiter.WaitContext(ctx, checker, options...)
π Example: Parallel Service Checking
checkers := []checker.Checker{
redis.New("redis://localhost:6379"),
postgresql.New("postgres://user:pass@localhost:5432/db"),
http.New("http://localhost:8080/health"),
}
err := waiter.WaitParallelContext(
ctx,
checkers,
waiter.WithTimeout(time.Minute),
waiter.WithBackoffPolicy(waiter.BackoffPolicyExponential),
)
π Example: Custom Checker Implementation
type FileChecker struct {
filePath string
minSize int64
}
func (f *FileChecker) Identity() (string, error) {
return fmt.Sprintf("file(%s)", f.filePath), nil
}
func (f *FileChecker) Check(ctx context.Context) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
fileInfo, err := os.Stat(f.filePath)
if err != nil {
if os.IsNotExist(err) {
return checker.NewExpectedError(
"file does not exist",
err,
"path", f.filePath,
)
}
return err
}
if fileInfo.Size() < f.minSize {
return checker.NewExpectedError(
"file is smaller than expected",
nil,
"path", f.filePath,
"actual_size", fileInfo.Size(),
"expected_min_size", f.minSize,
)
}
return nil
}
For more detailed examples with complete code, see the examples/pkg directory. Each example is in its own directory with a runnable main.go
file.
π€ Contributing
π Reporting Issues
If you encounter a bug or have a feature request, please open an issue:
Please include as much information as possible, including:
- Wait4X version
- Command-line arguments
- Expected vs. actual behavior
- Any error messages
π» Code Contributions
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name
- Make your changes
- Add tests for your changes
- Run the tests:
make test
- Commit your changes:
git commit -am 'Add awesome feature'
- Push the branch:
git push origin feature/your-feature-name
- Create a Pull Request
π License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Copyright 2019-2025 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.
Credits
The project logo is based on the "Waiting Man" character (Zhdun) and is used with attribution to the original creator.