mcpField
G
graceful-shutdown

graceful-shutdown

github.com/aj-geddesDevelopment373436 installsUpdated 34w ago
Repository

About graceful-shutdown

A software-development skill for implementing orderly process shutdowns. It helps teams complete in-flight requests, close connections, and release resources during deployments, restarts, and long-running jobs.

Key features

  1. 01Signal handling for SIGTERM and SIGINT
  2. 02Completion of in-flight requests
  3. 03Shutdown timeouts
  4. 04Database connection cleanup
  5. 05Shutdown support for servers and workers

Use cases

  1. 01Shutting down services during rolling updates
  2. 02Draining requests before server restarts
  3. 03Cleaning up database pools
  4. 04Stopping background workers safely

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill graceful-shutdown

After installing, type/graceful-shutdownin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
database-connection-pool-shutdown.md
expressjs-graceful-shutdown.md
kubernetes-aware-shutdown.md
pm2-graceful-shutdown.md
pythonflask-graceful-shutdown.md
worker-process-shutdown.md
scripts/
validate-config.sh
templates/
config-starter.yaml

Details

From the project README

Graceful Shutdown

Table of Contents

Overview

Implement proper shutdown procedures to ensure all requests are completed, connections are closed, and resources are released before process termination.

When to Use

  • Kubernetes/Docker deployments
  • Rolling updates and deployments
  • Server restarts
  • Load balancer drain periods
  • Zero-downtime deployments
  • Process managers (PM2, systemd)
  • Long-running background jobs
  • Database connection cleanup

Quick Start

Minimal working example:

import express from "express";
import http from "http";

class GracefulShutdownServer {
  private app: express.Application;
  private server: http.Server;
  private isShuttingDown = false;
  private activeConnections = new Set<any>();
  private shutdownTimeout = 30000; // 30 seconds

  constructor() {
    this.app = express();
    this.server = http.createServer(this.app);
    this.setupMiddleware();
    this.setupRoutes();
    this.setupShutdownHandlers();
  }

  private setupMiddleware(): void {
    // Track active connections
    this.app.use((req, res, next) => {
      if (this.isShuttingDown) {
        res.set("Connection", "close");
        return res.status(503).json({
          error: "Server is shutting down",
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Express.js Graceful ShutdownExpress.js Graceful Shutdown
Kubernetes-Aware ShutdownKubernetes-Aware Shutdown
Worker Process ShutdownWorker Process Shutdown
Database Connection Pool ShutdownDatabase Connection Pool Shutdown
PM2 Graceful ShutdownPM2 Graceful Shutdown
Python/Flask Graceful ShutdownPython/Flask Graceful Shutdown

Best Practices

✅ DO
  • Handle SIGTERM and SIGINT signals
  • Stop accepting new requests immediately
  • Wait for in-flight requests to complete
  • Set reasonable shutdown timeouts
  • Close database connections properly
  • Flush logs and metrics
  • Fail health checks during shutdown
  • Test shutdown procedures
  • Log shutdown progress
  • Use graceful shutdown in containers
❌ DON'T
  • Ignore shutdown signals
  • Force kill processes without cleanup
  • Set unreasonably long timeouts
  • Skip resource cleanup
  • Forget to close connections
  • Block shutdown indefinitely

Comments

Markdown supported