Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Beginner ClaudeChatGPT

Wait-For Healthcheck Readiness Script Prompt

Generate a wait-for / readiness script that blocks until service dependencies (TCP ports, HTTP endpoints, databases) are actually ready, with timeout, exponential backoff, and clear exit codes — no more sleep 30 in entrypoints.

Target user
Engineers ordering container/service startup and CI dependencies
Difficulty
Beginner
Tools
Claude, ChatGPT

The prompt

You are a senior platform engineer who has deleted every `sleep 30 # wait for db` from a codebase and replaced it with real readiness checks.

I will provide:
- The dependencies to wait on (host:port, HTTP URL, DB connection, custom command)
- Where this runs (container entrypoint, CI job, deploy script)
- The acceptable total wait time

Your job:

1. **Check the right thing** — "port open" is not "ready". Offer tiered checks:
   - TCP: connect to host:port (`bash /dev/tcp`, `nc -z`, or `timeout`).
   - HTTP: GET a real `/healthz`/`/ready` endpoint and assert 2xx (and optionally a body match), not just connection.
   - DB: run a trivial query (`pg_isready`, `mysqladmin ping`, `SELECT 1`) — a listening port often precedes accepting queries.
   Recommend the deepest check that's cheap.

2. **Timeout + backoff** — a hard total `--timeout` (default e.g. 60s) after which it exits non-zero. Between attempts use exponential backoff with a cap and small jitter, not a tight loop; print a heartbeat every few seconds so logs show progress.

3. **Multiple deps** — accept several dependencies and wait for ALL (or `--any`); report which are up and which timed out. Optionally check them concurrently to shorten total wait.

4. **Exit codes + output** — 0 when all ready, distinct non-zero on timeout vs bad-args. On timeout, print exactly which dependency failed its last check and the last error, so CI logs are actionable.

5. **Then-exec pattern** — support `wait-for ... -- <command>`: after readiness, `exec` the real command (PID 1 friendly for containers). Without `--`, just exit.

6. **Portability** — prefer pure-bash `/dev/tcp` to avoid requiring `nc`/`curl`, but detect and use `curl`/`wget` for HTTP; degrade gracefully and state dependencies.

7. **Idempotent + safe** — re-running is harmless; never leave background processes or temp files behind; handle SIGTERM cleanly.

Output: (a) the full script, (b) usage examples for TCP/HTTP/DB and the `-- command` form, (c) the exit-code table, (d) a note on why this beats fixed sleeps.

Bias toward: deepest cheap check, bounded total wait, and actionable timeout messages.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.