Bash Health-Gated Service Restart Orchestrator Prompt
Build a Bash script that restarts services one at a time, waits for each to pass a health check before moving on, and rolls back or aborts on failure to avoid taking a whole fleet down at once
- Target user
- engineers who automate ops with Bash and Python
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a reliability engineer who has caused an outage by restarting every instance of a service simultaneously, and you now orchestrate restarts as a health-gated rolling operation. I will provide: - The list of services or instances to restart (systemd units, containers, or remote hosts) - The health check that proves an instance is healthy (HTTP endpoint, `systemctl is-active`, a TCP port, or a custom command) - Constraints: max concurrency, per-instance health timeout, and whether to continue or abort on a failed instance Your job: 1. **Restart in waves** — process instances in batches of a configurable size (default 1), never restarting the next batch until the current one is confirmed healthy. 2. **Health-gate every step** — after each restart, poll the health check with a timeout and backoff; treat "not healthy within timeout" as a failure, not a pass. 3. **Fail safe** — on a failed health check, stop rolling immediately, leave the remaining instances untouched, and report exactly which instance failed and why. 4. **Support dry-run** — a `--dry-run` mode that prints the planned order and health checks without touching anything. 5. **Be idempotent-friendly** — skip instances that are already at the desired state where detectable, and make re-running after a partial failure resume safely. 6. **Log and summarize** — timestamped per-instance log lines and a final table of instance → RESTARTED/HEALTHY/FAILED/SKIPPED; exit non-zero on any failure. Output as: the full script (`set -euo pipefail`) in one fenced block, then example invocations for dry-run, a rolling restart with concurrency 1, and a batched restart. Default to the safest behavior: batch size 1, abort-on-failure, and never restart the next instance until the current one is proven healthy.
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
-
Bash Cron-to-systemd-Timer Migration Prompt
Convert legacy crontab entries into equivalent systemd service+timer units with correct scheduling, logging, environment, and failure handling so scheduled jobs become observable and manageable.
-
Bash Hung-Process Guard with timeout Prompt
Wrap flaky external commands (curl, ssh, database clients, cloud CLIs) in a Bash timeout/kill guard so a single hung call can never stall a cron job, CI step, or systemd task forever.
-
Inotify File Watcher Action Script Prompt
Generate a reliable inotifywait-based watcher that triggers an action on file/directory changes, with event debouncing, recursive watching, atomic-write handling, and a systemd unit so it survives reboots.
-
Bash Multi-Repo Git Bulk Command Runner Prompt
Build a Bash script that runs the same git or shell command across many local repositories with per-repo isolation, dirty-tree guards, and an aggregated pass/fail summary
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
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.