### Development Workflow: Local Setup with waitup Source: https://github.com/grok-rs/waitup/wiki/Examples This bash script outlines a local development setup process. It starts infrastructure services using docker-compose and then uses waitup to ensure PostgreSQL, Redis, and Elasticsearch are ready before starting the application with 'npm run dev'. It includes a 60-second timeout and verbose output. ```bash #!/bin/bash # dev-setup.sh echo "Starting development environment..." # Start infrastructure services docker-compose up -d postgres redis elasticsearch # Wait for all services to be ready waitup \ localhost:5432 \ localhost:6379 \ localhost:9200 \ --all --timeout 60s --verbose echo "All services ready! Starting application..." # Start the application npm run dev ``` -------------------------------- ### Install Rust and waitup on macOS using rustup Source: https://github.com/grok-rs/waitup/wiki/Installation Guides users on installing Rust using rustup and then installing waitup from source on macOS. It includes the necessary commands for both Rust installation and waitup setup. ```bash # Install Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env # Install waitup git clone https://github.com/grok-rs/waitup.git cd waitup cargo install --path . ``` -------------------------------- ### Quick Install waitup using Cargo Source: https://github.com/grok-rs/waitup/wiki/Installation Installs waitup by cloning the repository, navigating into the directory, and using Cargo to build and install the package. It also includes a command to verify the installation. ```bash git clone https://github.com/grok-rs/waitup.git && cd waitup && cargo install --path . waitup --version ``` -------------------------------- ### Install waitup on Windows using rustup or winget Source: https://github.com/grok-rs/waitup/wiki/Installation Details how to install waitup on Windows, either by using the rustup installer or the winget package manager to install Rust, followed by cloning and installing waitup from source. ```powershell # Install Rust (download from https://rustup.rs/) # Or use winget: winget install Rustlang.Rustup # Install waitup git clone https://github.com/grok-rs/waitup.git cd waitup cargo install --path . ``` -------------------------------- ### Development Installation of waitup Source: https://github.com/grok-rs/waitup/wiki/Installation Details the steps for setting up waitup for development purposes. This includes cloning the repository, installing development dependencies, running tests, and performing a forced installation. ```bash git clone https://github.com/grok-rs/waitup.git cd waitup # Install development dependencies cargo build # Run tests cargo test # Install for development (force reinstall) cargo install --path . --force ``` -------------------------------- ### Install Rust and waitup on Linux (Ubuntu/Debian) Source: https://github.com/grok-rs/waitup/wiki/Installation Guides users on installing Rust using rustup and then installing waitup from source on Ubuntu/Debian-based Linux distributions. ```bash # Install Rust (if needed) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env # Install waitup git clone https://github.com/grok-rs/waitup.git cd waitup cargo install --path . ``` -------------------------------- ### Build and Install waitup from Source Source: https://github.com/grok-rs/waitup/wiki/Installation This snippet details the process of building and installing waitup from its source code. It involves cloning the repository, changing the directory, and then using Cargo to install the package. Verification commands are also included. ```bash git clone https://github.com/grok-rs/waitup.git cd waitup cargo install --path . waitup --help waitup --version ``` -------------------------------- ### Install Rust and waitup on Linux (CentOS/RHEL/Fedora) Source: https://github.com/grok-rs/waitup/wiki/Installation Provides instructions for installing Rust via rustup and then installing waitup from source on CentOS, RHEL, and Fedora systems. It also includes steps for installing necessary build tools. ```bash # Install Rust (if needed) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env # Install build tools (if needed) sudo yum groupinstall "Development Tools" # CentOS/RHEL sudo dnf groupinstall "Development Tools" # Fedora # Install waitup git clone https://github.com/grok-rs/waitup.git cd waitup cargo install --path . ``` -------------------------------- ### Dockerfile Integration with Waitup Source: https://github.com/grok-rs/waitup/wiki/Examples Demonstrates how to install and use waitup within a Dockerfile to ensure service dependencies are met before the main application starts. ```dockerfile FROM node:18-alpine # Install waitup COPY --from=waitup:alpine /usr/local/bin/waitup /usr/local/bin/waitup COPY package*.json ./ RUN npm install COPY . . # Wait for dependencies before starting ENTRYPOINT ["waitup", "postgres:5432", "redis:6379", "--timeout", "120s", "--", "npm", "start"] ``` -------------------------------- ### Cross-Compilation Setup for Waitup Source: https://github.com/grok-rs/waitup/wiki/Developer-Guide Details the process of setting up and using cross-compilation for the waitup project. It covers installing 'cross' and building binaries for various target architectures. ```bash # Install cross # cargo install cross # Build for multiple targets # cross build --target x86_64-unknown-linux-gnu --release # cross build --target x86_64-apple-darwin --release # cross build --target x86_64-pc-windows-gnu --release # cross build --target aarch64-unknown-linux-gnu --release # Test cross-compiled binaries # docker run --rm -v $(pwd):/app alpine /app/target/x86_64-unknown-linux-gnu/release/waitup --help ``` -------------------------------- ### Development Workflow: Testing Environment Setup Source: https://github.com/grok-rs/waitup/wiki/Examples This bash script prepares a testing environment by starting services via docker-compose and then using waitup to confirm the readiness of the test database and cache. It specifies a 30-second timeout and a 1-second interval before running tests and cleaning up. ```bash #!/bin/bash # test-env.sh # Start test services docker-compose -f docker-compose.test.yml up -d # Wait for test database and cache waitup \ localhost:5433 \ localhost:6380 \ --timeout 30s \ --interval 1s # Run tests npm test # Cleanup docker-compose -f docker-compose.test.yml down ``` -------------------------------- ### JSON Configuration Example for Waitup Source: https://github.com/grok-rs/waitup/wiki/Configuration An example JSON file defining services with multiple targets and strategies for waitup. ```json { "services": { "web": { "targets": ["api:8080", "worker:8081"], "timeout": "60s", "strategy": "all" }, "data": { "targets": ["postgres:5432", "redis:6379"], "timeout": "120s", "strategy": "all" } } } ``` -------------------------------- ### Jenkins Pipeline: Setup and Wait for Services Source: https://github.com/grok-rs/waitup/wiki/Examples This Jenkins pipeline defines stages for setup, waiting for services, and testing. It clones and installs waitup, then uses it to wait for PostgreSQL and Redis on localhost with a 120-second timeout and verbose output before executing tests. ```groovy pipeline { agent any stages { stage('Setup') { steps { sh ''' git clone https://github.com/grok-rs/waitup.git cd waitup cargo install --path . ''' } } stage('Wait for Services') { steps { sh ''' docker-compose up -d postgres redis waitup localhost:5432 localhost:6379 --timeout 120s --all --verbose ''' } } stage('Test') { steps { sh 'npm test' } } } } ``` -------------------------------- ### Verify Waitup Installation Source: https://github.com/grok-rs/waitup/wiki/Installation Check if waitup is installed correctly by verifying its version and testing basic functionality. This includes running waitup with a target host and port, and checking for command completions. ```bash # Check version waitup --version # Test basic functionality waitup google.com:80 --timeout 5s # Verify completions (if installed) waitup # Should show available options ``` -------------------------------- ### Generate Bash Shell Completions for waitup Source: https://github.com/grok-rs/waitup/wiki/Installation Shows how to generate and install shell completion scripts for waitup in Bash. It provides instructions for both system-wide and user-specific installations. ```bash sudo waitup --generate-completion bash > /usr/share/bash-completion/completions/waitup mkdir -p ~/.local/share/bash-completion/completions waitup --generate-completion bash > ~/.local/share/bash-completion/completions/waitup ``` -------------------------------- ### Install waitup on Windows using WSL2 Source: https://github.com/grok-rs/waitup/wiki/Installation Explains how to install waitup on Windows by utilizing the Windows Subsystem for Linux (WSL2). It directs users to follow the Linux installation instructions within the WSL2 environment. ```bash # In WSL2, follow Linux instructions curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env git clone https://github.com/grok-rs/waitup.git cd waitup cargo install --path . ``` -------------------------------- ### GitHub Actions: Install and Use waitup Source: https://github.com/grok-rs/waitup/wiki/Examples This GitHub Actions workflow demonstrates installing waitup from source and then using it to wait for a PostgreSQL service on localhost:5432 before running tests. It includes steps for checking out the code, installing via cargo, and executing the waitup command with a 60-second timeout and verbose output. ```yaml name: Test on: [push, pull_request] jobs: test: runs-on: ubuntu-latest services: postgres: image: postgres:13 env: POSTGRES_PASSWORD: postgres options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - uses: actions/checkout@v3 - name: Install waitup run: | git clone https://github.com/grok-rs/waitup.git cd waitup cargo install --path . - name: Wait for services run: | waitup localhost:5432 --timeout 60s --verbose - name: Run tests run: npm test ``` -------------------------------- ### waitup Invalid Configuration Examples Source: https://github.com/grok-rs/waitup/wiki/Configuration Shows examples of invalid waitup configurations that will cause startup failures, such as max-interval less than interval or retry-limit of zero. ```bash # These will fail waitup target:port --interval 60s --max-interval 30s # max < interval waitup target:port --timeout 10s --connection-timeout 30s # connection > total waitup target:port --retry-limit 0 # must be > 0 ``` -------------------------------- ### YAML Configuration Example for Waitup Source: https://github.com/grok-rs/waitup/wiki/Configuration An example YAML file defining default and service-specific configurations for waitup. ```yaml # waitup-config.yml default: timeout: "60s" interval: "2s" services: database: target: "postgres:5432" timeout: "120s" interval: "5s" cache: target: "redis:6379" timeout: "30s" interval: "1s" ``` -------------------------------- ### Use waitup in a Dockerfile Source: https://github.com/grok-rs/waitup/wiki/Installation Provides an example of a multi-stage Docker build to include waitup in a Debian-based image. It copies the compiled binary from a Rust build stage to the final slim image. ```dockerfile FROM rust:1.70 as builder WORKDIR /app COPY . . RUN cargo build --release FROM debian:bookworm-slim RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* COPY --from=builder /app/target/release/waitup /usr/local/bin/waitup ENTRYPOINT ["waitup"] ``` -------------------------------- ### waitup CLI Examples Source: https://github.com/grok-rs/waitup/wiki/Home Examples of using the waitup command-line interface to wait for services before starting applications or checking multiple services with HTTP health endpoints. Also shows integration with Docker Compose. ```bash # Wait for a database before starting your app waitup postgres:5432 --timeout 60s -- npm start # Check multiple services with HTTP health endpoints waitup db:5432 redis:6379 https://api/health --all --timeout 2m # Use in Docker Compose docker-compose run app waitup postgres:5432 -- ./start-app.sh ``` -------------------------------- ### Install waitup on Alpine Linux Source: https://github.com/grok-rs/waitup/wiki/Installation Details the process of installing waitup on Alpine Linux. This involves installing Rust and Cargo dependencies using apk, cloning the repository, and then installing waitup using Cargo. ```bash # Install dependencies apkg add rust cargo git # Install waitup git clone https://github.com/grok-rs/waitup.git cd waitup cargo install --path . ``` -------------------------------- ### Build waitup Docker Image Source: https://github.com/grok-rs/waitup/wiki/Installation Demonstrates how to build a Docker image for waitup. It includes commands to build the standard image and a smaller Alpine-based image, along with instructions to test their functionality. ```bash # Build the standard image docker build -t waitup . # Test it works docker run --rm waitup --version # Build Alpine image (smaller size ~10MB) docker build -f Dockerfile.alpine -t waitup:alpine . # Test it works docker run --rm waitup:alpine --version ``` -------------------------------- ### waitup Service-Specific Configuration Examples Source: https://github.com/grok-rs/waitup/wiki/Configuration Provides examples of configuring waitup with different timeouts and intervals tailored for specific services like databases, caches, and APIs. ```bash # Database (slow startup) waitup postgres:5432 --timeout 120s --interval 5s # Cache (fast startup) waitup redis:6379 --timeout 30s --interval 1s # API (health check) waitup https://api.com/health --expect-status 200 --timeout 60s ``` -------------------------------- ### Install Waitup on Alpine Linux Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Provides instructions for installing Waitup on Alpine Linux, including the prerequisite 'gcompat' package, or using the Docker image. ```bash # Install gcompat if needed apk add gcompat ``` -------------------------------- ### Generate Zsh Shell Completions for waitup Source: https://github.com/grok-rs/waitup/wiki/Installation Provides instructions for generating and installing shell completion scripts for waitup in Zsh. This involves creating the necessary directory and outputting the completion script. ```bash mkdir -p ~/.local/share/zsh/site-functions waitup --generate-completion zsh > ~/.local/share/zsh/site-functions/_waitup ``` -------------------------------- ### Install waitup on macOS using Homebrew Source: https://github.com/grok-rs/waitup/wiki/Installation Explains how to install waitup on macOS using Homebrew. It assumes Rust is already installed via Homebrew and then proceeds to clone and install waitup from source. ```bash # Install Rust brew install rust # Install waitup git clone https://github.com/grok-rs/waitup.git cd waitup cargo install --path . ``` -------------------------------- ### Configure waitup in Docker Compose Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Example of how to configure waitup within a docker-compose.yml file to wait for a service like PostgreSQL before starting the application. ```yaml services: app: command: ["waitup", "postgres:5432", "--", "npm", "start"] depends_on: - postgres postgres: image: postgres:15 ``` -------------------------------- ### Generate Fish Shell Completions for waitup Source: https://github.com/grok-rs/waitup/wiki/Installation Details how to generate and install shell completion scripts for waitup in the Fish shell. This involves outputting the completion script to the appropriate Fish configuration directory. ```bash waitup --generate-completion fish > ~/.config/fish/completions/waitup.fish ``` -------------------------------- ### Systemd Service Configuration Source: https://github.com/grok-rs/waitup/wiki/Examples A systemd service unit file that configures an application to start. It includes a pre-start command using waitup to ensure database and Redis are available before the main application starts. It also defines restart policies. ```ini [Unit] Description=My Application After=network.target [Service] Type=forking ExecStartPre=/usr/local/bin/waitup postgres:5432 redis:6379 --timeout 60s ExecStart=/opt/myapp/start.sh Restart=always RestartSec=10 [Install] WantedBy=multi-user.target ``` -------------------------------- ### Install waitup from Source Source: https://github.com/grok-rs/waitup/blob/main/README.md This example provides the bash commands to clone the waitup repository from GitHub, navigate into the directory, and install it using Cargo, the Rust package manager. ```Bash # Clone and install in one step git clone https://github.com/grok-rs/waitup.git && cd waitup && cargo install --path . ``` ```Bash # Verify installation waitup --version ``` ```Bash # 1. Clone the repository git clone https://github.com/grok-rs/waitup.git cd waitup # 2. Build and install cargo install --path . # 3. Verify installation waitup --help ``` -------------------------------- ### Cross-Compile waitup for Various Platforms Source: https://github.com/grok-rs/waitup/wiki/Installation Demonstrates how to cross-compile waitup for different target architectures and operating systems using the `cross` tool. This includes building for Linux (static and ARM64), Windows, and macOS (Intel and ARM). ```bash # Install cross-compilation tool cargo install cross # Build for different platforms cross build --target x86_64-unknown-linux-musl --release # Linux static cross build --target x86_64-pc-windows-gnu --release # Windows cross build --target x86_64-apple-darwin --release # macOS Intel cross build --target aarch64-apple-darwin --release # macOS ARM cross build --target aarch64-unknown-linux-gnu --release # Linux ARM64 ``` -------------------------------- ### waitup Valid Configuration Examples Source: https://github.com/grok-rs/waitup/wiki/Configuration Illustrates valid combinations of waitup configuration options, including timeout, interval, max-interval, and retry-limit. ```bash # These are valid waitup target:port --timeout 60s --interval 1s waitup target:port --timeout 60s --max-interval 30s waitup target:port --retry-limit 10 ``` -------------------------------- ### Generate PowerShell Shell Completions for waitup Source: https://github.com/grok-rs/waitup/wiki/Installation Shows how to generate a PowerShell script for waitup shell completions, which can then be used to enhance the command-line experience in Windows PowerShell. ```powershell waitup --generate-completion powershell > waitup.ps1 ``` -------------------------------- ### Service-Specific Waitup Configurations Source: https://github.com/grok-rs/waitup/wiki/Configuration Examples of using waitup with specific timeouts and intervals for different types of services. ```bash # Fast services waitup redis:6379 --timeout 30s # Slow services waitup postgres:5432 --timeout 120s --interval 5s # External services waitup external-api.com:443 --timeout 60s --retry-limit 10 ``` -------------------------------- ### Install Waitup via Homebrew Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Installs the Waitup tool using the Homebrew package manager on macOS or Linux. ```bash brew install waitup ``` -------------------------------- ### Startup Script with Dependency Wait Source: https://github.com/grok-rs/waitup/wiki/Examples An application startup script that uses waitup to ensure all required dependencies (PostgreSQL, Redis, Auth Service) are available before starting the main application. It uses the '--all' flag for mandatory availability and a verbose output. ```bash #!/bin/bash # app-startup.sh set -e # Exit on any error echo "Waiting for dependencies..." # Wait for required services waitup \ postgres:5432 \ redis:6379 \ https://auth-service:8080/health \ --all --timeout 300s --verbose echo "Dependencies ready, starting application..." # Start the application exec "$@" ``` -------------------------------- ### Test Targets Individually with Waitup Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Provides an example of testing each target service individually with waitup to isolate which one might be causing issues. ```bash waitup db:5432 --timeout 30s waitup redis:6379 --timeout 30s waitup api:8080 --timeout 30s ``` -------------------------------- ### Bash Completion Setup Source: https://github.com/grok-rs/waitup/wiki/Configuration Instructions for enabling bash tab completion for the waitup command. ```bash # Enable completions waitup --generate-completion bash > ~/.local/share/bash-completion/completions/waitup source ~/.bashrc # Now tab completion works waitup # Shows available options ``` -------------------------------- ### Use Lightweight waitup Docker Image Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Dockerfile example specifying the use of the lightweight alpine version of the waitup Docker image. ```dockerfile FROM ghcr.io/grok-rs/waitup:alpine ``` -------------------------------- ### Install Development Tools with Cargo Source: https://github.com/grok-rs/waitup/wiki/Developer-Guide Installs essential Rust development tools including cargo-watch, cargo-expand, cargo-audit, and cargo-deny for managing dependencies and code quality. Optionally installs faster test runners and coverage reporting tools. ```bash # Required tools rustup install stable cargo install cargo-watch cargo-expand cargo-audit cargo install --locked cargo-deny # Optional but recommended cargo install cargo-nextest # Faster test runner cargo install cargo-llvm-cov # Coverage reporting ``` -------------------------------- ### Update Waitup via Git and Cargo Source: https://github.com/grok-rs/waitup/wiki/Installation To update waitup to the latest version, first pull the latest changes from the main branch of the repository using Git. Then, reinstall the tool using Cargo, forcing the installation if necessary. ```bash # Pull latest changes cd waitup git pull origin main # Reinstall cargo install --path . --force ``` -------------------------------- ### Development Setup with Cargo Source: https://github.com/grok-rs/waitup/blob/main/README.md Provides commands for setting up the development environment for waitup using Cargo. This includes cloning the repository, building, testing, and installing the tool locally. ```bash # Clone with full history git clone https://github.com/grok-rs/waitup.git cd waitup # Install development dependencies cargo build # Run tests cargo test # Install for development cargo install --path . --force ``` -------------------------------- ### Optimize Waitup Build Performance Source: https://github.com/grok-rs/waitup/wiki/Installation Build waitup with optimizations for better performance. This can be achieved by setting RUSTFLAGS to target specific CPU features or by using the release profile during the build process. ```rust # Build with maximum optimizations RUSTFLAGS="-C target-cpu=native" cargo install --path . --release # Or use the pre-configured release profile cargo build --release cp target/release/waitup ~/.cargo/bin/ ``` -------------------------------- ### Run Official waitup Docker Image Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Example of running the official waitup Docker image directly from Docker Hub, specifying the target host and port. ```bash docker run --rm ghcr.io/grok-rs/waitup:alpine hostname:port ``` -------------------------------- ### Docker Compose Integration Example Source: https://github.com/grok-rs/waitup/blob/main/README.md Provides an example of how to integrate waitup into a Docker Compose setup, using it as a dependency to ensure a service (e.g., an application) starts only after its database is available. ```yaml services: app: image: myapp depends_on: - db command: ["waitup", "db:5432", "--", "npm", "start"] db: image: postgres ``` -------------------------------- ### Kubernetes Pod with Waitup Init Container Source: https://github.com/grok-rs/waitup/wiki/Examples Illustrates how to use waitup as an init container in a Kubernetes Pod to ensure that required services are available before the main application container starts. ```yaml apiVersion: v1 kind: Pod metadata: name: myapp spec: initContainers: - name: wait-for-deps image: waitup:alpine command: ["waitup"] args: - "postgres:5432" - "redis:6379" - "https://external-api.com/health" - "--timeout" - "300s" - "--all" containers: - name: app image: myapp:latest ``` -------------------------------- ### Update Rust Toolchain Source: https://github.com/grok-rs/waitup/wiki/Installation If build errors occur due to an outdated Rust version, update your Rust toolchain to the latest stable version using rustup. This ensures you have the most recent compiler and associated tools. ```bash # Update Rust to latest version rustup update stable rustup default stable ``` -------------------------------- ### Update Docker Base Images Source: https://github.com/grok-rs/waitup/wiki/Installation When encountering Docker build failures, ensure you are using the latest base images for Rust and Debian. Pulling the latest versions can resolve compatibility issues. ```bash # Ensure you have the latest base images docker pull rust:1.70 docker pull debian:bookworm-slim # Clear Docker cache if needed docker system prune -f ``` -------------------------------- ### Microservices: Wait for API Gateway Dependencies Source: https://github.com/grok-rs/waitup/wiki/Examples This bash script illustrates waiting for backend services and an external API's health endpoint before starting an API gateway. It uses '--all' with a 2-minute timeout and specifies a local script to execute after readiness is confirmed. ```bash # Wait for backend services before starting gateway waitup \ auth-service:8080 \ user-service:8081 \ product-service:8082 \ https://external-payment-api.com/health \ --all --timeout 2m \ -- ./start-gateway.sh ``` -------------------------------- ### Docker Compose Up Command for Tutorial Source: https://github.com/grok-rs/waitup/wiki/Tutorials Starts the Docker Compose services defined in the 'tutorial-compose.yml' file. ```bash docker-compose -f tutorial-compose.yml up ``` -------------------------------- ### Docker Compose: Multi-Stage Waiting Source: https://github.com/grok-rs/waitup/wiki/Tutorials This example shows how to use Waitup in Docker Compose to manage complex dependency chains, ensuring services like PostgreSQL and Redis are available before starting dependent services like a migration tool or the main application. ```yaml version: "3.8" services: postgres: image: postgres:15 environment: POSTGRES_PASSWORD: password redis: image: redis:alpine migrate: image: ghcr.io/grok-rs/waitup:alpine command: | sh -c " waitup postgres:5432 --timeout 60s && echo 'Running migrations...' && sleep 2 && echo 'Migrations complete' " depends_on: - postgres app: image: ghcr.io/grok-rs/waitup:alpine command: | sh -c " waitup postgres:5432 redis:6379 --timeout 30s && echo 'All dependencies ready, starting app...' " depends_on: - postgres - redis - migrate ``` -------------------------------- ### waitup Multi-Environment Configuration Loading Source: https://github.com/grok-rs/waitup/wiki/Configuration Shows how to load different environment configurations (development, staging, production) using source commands before running waitup. ```bash # development.env # WAITUP_TIMEOUT=30s # WAITUP_INTERVAL=1s # staging.env # WAITUP_TIMEOUT=120s # WAITUP_INTERVAL=2s # production.env # WAITUP_TIMEOUT=300s # WAITUP_INTERVAL=5s # Usage source production.env waitup db:5432 redis:6379 --all ``` -------------------------------- ### Waitup Timeout Configuration Best Practices Source: https://github.com/grok-rs/waitup/wiki/Docker-and-Kubernetes This example shows how to set appropriate timeouts for Waitup based on the environment. Shorter timeouts are recommended for development clusters to get faster feedback, while longer timeouts are suitable for production clusters to ensure resilience. ```yaml # Development cluster (fast feedback) args: ["--timeout", "60s", "--interval", "2s"] # Production cluster (resilient) args: ["--timeout", "300s", "--interval", "5s"] ``` -------------------------------- ### Start Test Service (Python, Node.js, Docker) Source: https://github.com/grok-rs/waitup/wiki/Tutorials Demonstrates how to start a test HTTP server on port 8080 using Python, Node.js, or Docker for testing waitup. ```bash # Option 1: Using Python (if available) python3 -m http.server 8080 # Option 2: Using Node.js (if available) npx http-server -p 8080 # Option 3: Using Docker docker run -p 8080:80 nginx:alpine ``` -------------------------------- ### Waitup with Slow Startup Simulation Source: https://github.com/grok-rs/waitup/wiki/Tutorials Simulates a service with a slow startup time using Docker and configures waitup to successfully connect after the service is ready. ```bash # Start a container that takes 15 seconds to be ready docker run -d --name slow-start -p 9999:80 \ --health-cmd="sleep 15 && curl -f http://localhost/ || exit 1" \ --health-interval=5s \ nginx:alpine # Wait for it with appropriate settings waitup localhost:9999 --timeout 30s --interval 2s --verbose ``` -------------------------------- ### Get Individual Target Results with JSON Output Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Shows how to use the --json flag with waitup to get detailed results for each target when checking multiple targets simultaneously. ```bash # Use JSON output to see individual results waitup db:5432 redis:6379 api:8080 --json ``` -------------------------------- ### Connection Speed Testing Source: https://github.com/grok-rs/waitup/wiki/Examples Demonstrates using the 'time' command with waitup to measure how quickly services become available. It shows examples for testing a single fast service and comparing startup times for different database services. ```bash # Test how quickly services become available time waitup fast-service:8080 --timeout 10s # Compare startup times time waitup postgres:5432 --timeout 60s time waitup mysql:3306 --timeout 60s ``` -------------------------------- ### Basic Waitup Usage Source: https://github.com/grok-rs/waitup/wiki/Configuration Demonstrates basic usage of waitup with environment variables and command-line flags for timeouts. ```bash waitup target:port # Uses 60s from env var waitup target:port --timeout 30s # Uses 30s from flag (overrides env) ``` -------------------------------- ### Wait for Any Service with waitup Source: https://github.com/grok-rs/waitup/wiki/Tutorials Demonstrates using waitup with the '--any' flag to proceed as soon as at least one of the specified services becomes available. This is useful for primary/backup scenarios. ```bash # Primary and backup databases waitup primary-db:5432 backup-db:5432 --any --timeout 30s # For our example (both should work, so this will succeed quickly) waitup localhost:5432 localhost:6379 --any --timeout 10s ``` -------------------------------- ### Troubleshoot 'Command not found' Error Source: https://github.com/grok-rs/waitup/wiki/Installation If you encounter a 'command not found' error after installation, ensure that Cargo's bin directory is correctly added to your system's PATH environment variable. Reload your shell after making changes. ```bash # Ensure Cargo's bin directory is in your PATH echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc source ~/.bashrc ``` -------------------------------- ### Waitup for MySQL Source: https://github.com/grok-rs/waitup/wiki/Examples Provides examples for waiting on MySQL services, including handling slow startup times with longer timeouts and custom ports. ```bash # Wait for MySQL with longer timeout (slow startup) waitup mysql:3306 --timeout 120s --interval 5s # MySQL with custom port waitup mysql-server:3307 --timeout 60s ``` -------------------------------- ### Kubernetes Job with Dependency Waiting Source: https://github.com/grok-rs/waitup/wiki/Examples This example demonstrates how to use waitup as an init container in a Kubernetes Job to ensure a database is ready before the main migration container starts. It specifies the service to wait for ('postgres:5432') and a timeout of 300 seconds. ```yaml apiVersion: batch/v1 kind: Job metadata: name: migration-job spec: template: spec: initContainers: - name: wait-for-db image: waitup:alpine command: ["waitup", "postgres:5432", "--timeout", "300s"] containers: - name: migrate image: myapp:latest command: ["npm", "run", "migrate"] restartPolicy: Never ``` -------------------------------- ### Test waitup with Minimal Configuration Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting A basic test command for waitup with a short timeout and interval, useful for quick verification. ```bash # Simplest possible test waitup localhost:80 --timeout 5s --interval 1s ``` -------------------------------- ### Docker Compose with Waitup Source: https://github.com/grok-rs/waitup/wiki/Examples Provides an example of integrating waitup into a docker-compose.yml file as a service to ensure dependencies are met before application startup. ```yaml version: "3.8" services: app: image: myapp:latest depends_on: db-ready: condition: service_completed_successfully command: ["npm", "start"] db-ready: image: waitup:alpine command: ["waitup", "postgres:5432", "--timeout", "60s"] depends_on: - postgres postgres: image: postgres:15 environment: POSTGRES_PASSWORD: password ``` -------------------------------- ### Reduce waitup Retry Interval Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Example of reducing the retry interval for waitup to 100ms for faster checking of a service. ```bash waitup fast-service:8080 --interval 100ms ``` -------------------------------- ### Get waitup Version Information Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Command to display the version of the waitup tool, useful for reporting issues or checking compatibility. ```bash waitup --version ``` -------------------------------- ### Waitup for PostgreSQL Source: https://github.com/grok-rs/waitup/wiki/Examples Shows how to use waitup to ensure PostgreSQL is available before running database migrations or managing multiple PostgreSQL instances. ```bash # Wait for PostgreSQL before running migrations waitup postgres:5432 --timeout 60s -- npm run migrate # Multiple database instances waitup primary-db:5432 replica-db:5432 --any --timeout 30s ``` -------------------------------- ### Set waitup Connection Timeout Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Example of setting a specific connection timeout for waitup to 5 seconds when checking a slow service. ```bash waitup slow-service:8080 --connection-timeout 5s ``` -------------------------------- ### Running Commands After Success with waitup Source: https://github.com/grok-rs/waitup/wiki/Tutorials Shows how to execute a command or script immediately after waitup confirms that all specified services are ready. This is useful for starting applications or performing post-readiness tasks. ```bash # Run a command after services are ready waitup localhost:5432 localhost:6379 -- echo "Services are ready!" # More realistic example waitup localhost:5432 localhost:6379 -- npm start # With shell command waitup localhost:5432 -- sh -c "echo 'DB ready at $(date)'" ``` -------------------------------- ### Waitup Error Handling Example Source: https://github.com/grok-rs/waitup/wiki/Docker-and-Kubernetes This example shows a robust error handling strategy using Waitup within a shell script. It checks the exit status of Waitup and provides informative messages or executes alternative actions, such as logging related to the failed dependency. ```sh if waitup postgres:5432 --timeout 300s; then echo "Database ready" else echo "Database failed to start - check logs" kubectl logs -l app=postgres exit 1 fi ``` -------------------------------- ### Use JSON Output with jq for waitup Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Example of piping waitup's JSON output to jq to filter for targets that failed to connect. ```bash waitup db:5432 redis:6379 --json | jq '.targets[] | select(.success == false)' ``` -------------------------------- ### Configure Background Services in GitHub Actions Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Example of configuring a PostgreSQL service with health checks in a GitHub Actions workflow file (.github/workflows/test.yml). ```yaml # .github/workflows/test.yml services: postgres: image: postgres:15 options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ``` -------------------------------- ### Test Basic Connectivity with Waitup Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Demonstrates how to test basic network connectivity to a service using waitup. This involves specifying the host and port, along with a timeout duration. ```bash waitup localhost:80 --timeout 5s ``` -------------------------------- ### waitup Production Environment Configuration Source: https://github.com/grok-rs/waitup/wiki/Configuration Configures waitup with longer timeouts suitable for production environments and demonstrates its use in startup scripts. ```bash # Longer timeouts for production export WAITUP_TIMEOUT=300s export WAITUP_INTERVAL=5s export WAITUP_CONNECTION_TIMEOUT=30s # Use in startup scripts waitup postgres:5432 redis:6379 --all --timeout 300s -- npm start ``` -------------------------------- ### Get System Information Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Commands to retrieve system information such as kernel version (uname) and Docker version, helpful for debugging environment-specific problems. ```bash uname -a docker --version # if using Docker ``` -------------------------------- ### Set CI/CD Pipeline Timeouts with waitup Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Examples of setting timeouts for waitup in GitHub Actions and GitLab CI pipelines to prevent pipeline failures. ```bash # GitHub Actions waitup db:5432 --timeout 120s -- npm test # GitLab CI waitup db:5432 --timeout 2m -- ./run-tests.sh ``` -------------------------------- ### Command Execution Examples Source: https://github.com/grok-rs/waitup/blob/main/README.md Demonstrates how to execute a command after waitup successfully connects to the specified services. This is useful for orchestrating application startup sequences. ```bash # Run command after successful connection waitup db:5432 -- npm start # Multiple services before command waitup db:5432 redis:6379 --all -- ./start-app.sh ``` -------------------------------- ### Docker Compose Init Container Pattern Source: https://github.com/grok-rs/waitup/wiki/Tutorials Sets up a Docker Compose file demonstrating the init container pattern. An 'init-wait' service uses waitup to ensure the 'db' service is ready before the main 'app' service starts. ```yaml version: "3.8" services: db: image: postgres:15 environment: POSTGRES_PASSWORD: password app: image: alpine:latest command: ["sh", "-c", "echo 'App running with ready dependencies!'"] init: true depends_on: - init-wait init-wait: image: ghcr.io/grok-rs/waitup:alpine command: ["waitup", "db:5432", "--timeout", "30s", "--verbose"] depends_on: - db ``` -------------------------------- ### waitup Configuration Precedence Example Source: https://github.com/grok-rs/waitup/wiki/Configuration Demonstrates the precedence order for waitup configuration: command-line flags override environment variables, which override default values. ```bash # Example scenario: # Environment variable: WAITUP_TIMEOUT=120s # Command-line flag: --timeout 30s # waitup will use 30s for the timeout. ``` -------------------------------- ### Get Container IP Address Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Command to inspect a Docker container and retrieve its IP address, helpful for direct network communication within Docker. ```bash # Find container IP docker inspect postgres | grep IPAddress ``` -------------------------------- ### Basic waitup Usage Source: https://github.com/grok-rs/waitup/wiki/Tutorials Demonstrates the fundamental usage of the waitup command to check service availability. It shows how to specify services by host and port, and how command-line options can override environment variables. ```bash waitup service1:8080 waitup service2:8081 waitup service3:8082 --timeout 10s ``` -------------------------------- ### Basic TCP Connection Examples Source: https://github.com/grok-rs/waitup/blob/main/README.md Demonstrates basic usage of waitup for waiting on TCP services. It shows how to specify a host and port, and how to configure timeout and interval values. ```bash # Wait for a service to be ready waitup localhost:8080 # With timeout and custom interval waitup db:5432 --timeout 2m --interval 5s ``` -------------------------------- ### Enable Verbose Output in Waitup Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Shows how to enable verbose logging in waitup to get detailed information about its progress and any encountered issues during the waiting process. ```bash waitup localhost:80 --verbose ``` -------------------------------- ### Configure waitup Timeout in Kubernetes Init Container Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Kubernetes init container configuration example using waitup with a specified timeout to prevent premature restarts. ```yaml initContainers: - name: waitup-deps image: waitup:alpine command: ["waitup"] args: ["postgres:5432", "--timeout", "300s"] ``` -------------------------------- ### Dockerfile: Custom Application Integration with Waitup Source: https://github.com/grok-rs/waitup/wiki/Tutorials This Dockerfile demonstrates how to build a Rust application and integrate Waitup. Waitup is copied into the final image to ensure application dependencies are met before the application starts. ```dockerfile FROM rust:slim as builder WORKDIR /app COPY Cargo.* ./ COPY src ./src RUN cargo build --release FROM debian:bookworm-slim RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* # Install waitup COPY --from=ghcr.io/grok-rs/waitup:latest /usr/local/bin/waitup /usr/local/bin/waitup COPY --from=builder /app/target/release/myapp /usr/local/bin/myapp # Your app waits for dependencies, then starts CMD ["waitup", "postgres:5432", "redis:6379", "--timeout", "60s", "--", "myapp"] ``` -------------------------------- ### Run Waitup on Windows using WSL2 Source: https://github.com/grok-rs/waitup/wiki/Troubleshooting Demonstrates how to use Waitup within the Windows Subsystem for Linux (WSL2) by first entering the WSL environment and then executing the waitup command. ```bash wsl waitup hostname:port ``` -------------------------------- ### waitup Development Environment Aliases Source: https://github.com/grok-rs/waitup/wiki/Configuration Sets up convenient aliases for common waitup checks in a development environment, simplifying repeated commands. ```bash # ~/.bashrc or ~/.zshrc export WAITUP_TIMEOUT=60s export WAITUP_INTERVAL=1s # Quick dev checks alias wait-db='waitup localhost:5432' alias wait-redis='waitup localhost:6379' alias wait-api='waitup localhost:8080' ``` -------------------------------- ### Bash: DNS Optimization using IP Addresses Source: https://github.com/grok-rs/waitup/wiki/Performance Provides bash examples for optimizing DNS resolution in waitup by directly using IP addresses instead of hostnames. ```bash # Use IP addresses to skip DNS resolution waitup 192.168.1.100:8080 # Faster than hostname:8080 ``` -------------------------------- ### Uninstall Waitup Source: https://github.com/grok-rs/waitup/wiki/Installation Remove the waitup tool from your system. This can be done using Cargo's uninstall command or by manually removing the binary and associated shell completion files. ```bash # Remove the binary cargo uninstall waitup # Or manually remove rm ~/.cargo/bin/waitup # Remove shell completions (if installed) rm ~/.local/share/bash-completion/completions/waitup rm ~/.local/share/zsh/site-functions/_waitup rm ~/.config/fish/completions/waitup.fish ``` -------------------------------- ### Waitup with Timeouts Source: https://github.com/grok-rs/waitup/wiki/Examples Illustrates how to configure custom timeouts and retry intervals for waitup checks. This is useful for services that may take longer to start up or for quick checks with short deadlines. ```bash # Custom timeout and retry interval waitup slow-service:8080 --timeout 5m --interval 10s # Quick check with short timeout waitup api:8080 --timeout 10s ```