graceful-shutdown
Skill2 starsChanged 4 months agoMITView on GitHub
Make a service shut down cleanly on SIGTERM/SIGINT — stop accepting new work, drain in-flight requests, close DB/queue connections, and exit within the platform's grace period — so deploys and restarts don't drop requests or corrupt state. Use when the user says "add graceful shutdown", "handle SIGTERM", "drain connections on shutdown", "stop dropping requests during deploys", "close connections cleanly on exit", or "my app is killed mid-request".
1 other project uses a version of this.
Adopted by
Most recently taken up by
- jars-demo/jars-skillstheir own version, first seen Oct 25, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- jars-demo/jars-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository68 other files it gives its agents.
- a11ySkill
- api-docsSkill
- audit-logSkill
- benchmarkSkill
- bisectSkill
- cacheSkill
- changelogSkill
- cherry-pickSkill
- ci-setupSkill
- codeownersSkill
- commit-messageSkill
- connection-poolSkill
- contributingSkill
- coverageSkill
- db-migrateSkill
- dead-codeSkill
- debugSkill
- depsSkill
- diagramSkill
- dockerizeSkill
- docstringSkill
- e2eSkill
- env-exampleSkill
- error-handlingSkill
- explainSkill
- feature-flagSkill
- flaky-testSkill
- gitignoreSkill
- graphqlSkill
- healthcheckSkill
- i18nSkill
- idempotencySkill
- licenseSkill
- lint-fixSkill
- loggingSkill
- migrateSkill
- mockSkill
- onboardSkill
- optimizeSkill
- paginationSkill
- pr-descriptionSkill
- pre-commitSkill
- profileSkill
- prune-branchesSkill
- rate-limitSkill
- readmeSkill
- rebaseSkill
- refactorSkill
- regexSkill
- releaseSkill
- resolve-conflictsSkill
- retrySkill
- review-diffSkill
- scaffoldSkill
- secrets-scanSkill
- security-headersSkill
- seedSkill
- soft-deleteSkill
- sqlSkill
- squashSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Drain in-flight work with a bounded timeout: Wait for active requests/jobs to complete, but cap the wait (e.g.
- Very specific: line 23
Release resources in dependency order: After draining, close DB pools, cache/queue clients, and file handles, and flush logs/metrics/traces.
- Distinctive: line 25
Verify: Test that sending SIGTERM while a slow request is in flight lets that request finish and returns before exit, that new connections …
- Distinctive: line 30
Stop new work and fail readiness before closing the socket, so the balancer drains traffic first.
- Distinctive: line 31
Always bound the drain with a timeout under the platform's kill grace period — drain, but never block shutdown indefinitely.
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Runtime, server & signal signals
!grep -rilE "SIGTERM|SIGINT|process\\.on|signal\\.|shutdown|http\\.Server|createServer|express|fastify|nestjs|flask|fastapi|gunicorn|uvicorn|listen\\(|graceful" --include='*.*' package.json pyproject.toml go.mod Gemfile 2>/dev/null | grep -vE 'node_modules|\.git|dist|build' | head -8
Instructions
Make the service in $ARGUMENTS (or the app's entrypoint) terminate cleanly when the platform sends a shutdown signal, so an in-flight request is finished rather than severed and external resources are released. Reuse the project's server and connection objects rather than introducing a new lifecycle framework.
Method
- Handle the right signals. Trap
SIGTERM(what Kubernetes/Docker/systemd send) andSIGINT(Ctrl-C in dev). Run the shutdown routine once and guard against re-entry if a second signal arrives. - Stop accepting new work first. Close the listening socket / stop the HTTP server from taking new connections, and if the app pulls from a queue, stop consuming. Existing in-flight requests keep running; new ones are refused (or shed to another instance).
- Fail readiness immediately. Flip the readiness probe to unhealthy at the start of shutdown so the load balancer / orchestrator stops routing new traffic before the socket closes (see the
healthcheckskill). In Kubernetes, expect traffic for a moment after SIGTERM — a short pre-drain delay avoids races. - Drain in-flight work with a bounded timeout. Wait for active requests/jobs to complete, but cap the wait (e.g. 10–30s, comfortably under the platform's kill grace period). If work exceeds the deadline, log what's still pending and proceed — never block forever.
- Release resources in dependency order. After draining, close DB pools, cache/queue clients, and file handles, and flush logs/metrics/traces. Close what depends on the network before the things it depends on.
- Exit with an honest code.
exit(0)on a clean drain; a non-zero code if shutdown timed out or errored. Don't leave the process hanging — the platform willSIGKILLit and undo the graceful intent. - Verify. Test that sending SIGTERM while a slow request is in flight lets that request finish and returns before exit, that new connections are refused during drain, and that the process exits within the deadline.
Rules
- Trap SIGTERM (and SIGINT for dev), make the handler idempotent, and never let a second signal trigger a second concurrent shutdown.
- Stop new work and fail readiness before closing the socket, so the balancer drains traffic first; then drain in-flight requests.
- Always bound the drain with a timeout under the platform's kill grace period — drain, but never block shutdown indefinitely.
- Close DB/queue/cache connections and flush telemetry after draining, in dependency order, then exit with a status code that reflects success or timeout.
- End by summarizing which signals are handled, the drain timeout and how it relates to the platform grace period, the readiness behavior, and what gets closed on the way out.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

