graceful-shutdown

Coordinate in-flight work, drain buffers, and run cleanup tasks on SIGTERM or SIGINT.

Updated Jan 30, 2026
One-click install
npx skills add https://github.com/jrmatherly/metorial-workspace --skill graceful-shutdown
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: graceful-shutdown
Source: https://github.com/jrmatherly/metorial-workspace/tree/main/.github/skills/graceful-shutdown
Command: npx skills add https://github.com/jrmatherly/metorial-workspace --skill graceful-shutdown

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Graceful shutdown ensures long-running processes terminate without data loss by tracking in-flight work, draining buffers, and executing cleanup callbacks as signals arrive.

Core Features & Use Cases

  • In-flight tracking and timeout handling to prevent stuck tasks during shutdown.
  • Buffer draining and resource cleanup to preserve state and releases resources gracefully.
  • Signal handling to intercept termination requests and coordinate orderly shutdown.

Quick Start

Get the shutdown manager instance, register signal handling, and attach cleanup and drain logic. Use trackJob to monitor ongoing work and completeJob when tasks finish, ensuring a safe and predictable shutdown sequence.

Frequently Asked Questions about graceful-shutdown

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle graceful shutdown for in-flight tasks when my server receives SIGTERM?

Graceful shutdown intercepts termination signals like SIGTERM to track in-flight jobs, drain buffers, and execute cleanup callbacks, preventing data loss when long-running services terminate.

What is the best way to drain buffers and run cleanup callbacks during a worker shutdown?

Buffer draining and resource cleanup preserve state by registering drain callbacks that execute during shutdown, ensuring queued data is processed and resources are released safely before exit.

Can I track in-flight jobs and enforce timeouts to prevent stuck tasks during shutdown?

Tracking in-flight jobs with timeout handling prevents stuck tasks by monitoring ongoing work and enforcing execution limits, ensuring a safe and predictable shutdown sequence for queue processors.

Does graceful shutdown work with async queue processors and long-running services?

Graceful shutdown applies to async long-running services, workers, and queue processors, coordinating signal handling and orderly termination to prevent data loss across these environments.

Why does my process lose buffered data when terminating on SIGINT?

Data loss occurs when SIGINT triggers immediate termination without draining buffers; registering drain callbacks intercepts the signal to flush queued data and run cleanup tasks before exiting.

How to register cleanup callbacks and signal handling for an orderly server shutdown?

Register signal handling to intercept termination requests, attach cleanup logic, and use trackJob with completeJob to monitor ongoing work, ensuring an orderly shutdown sequence for long-running processes.