返回 Skill 列表
extension
分类: 开发与工程无需 API Key

libsupervision

libsupervision - 进程监控系统。Supervisor 管理受 s6-svscan 启发的进程树。LongRunner 处理具有重启功能的持久进程。OneShot 处理单次执行任务。ProcessState 跟踪进程生命周期。LogWriter 管理进程日志。用于服务管理、进程控制以及优雅关闭处理。

person作者: jakexiaohubgithub

libsupervision Skill

When to Use

  • Managing long-running service processes
  • Implementing process supervision with restart
  • Running one-shot initialization tasks
  • Handling graceful shutdown across processes

Key Concepts

Supervisor: Manages a tree of processes, handling startup order and shutdown.

LongRunner: Process that restarts automatically on exit (for services).

OneShot: Process that runs once (for migrations, initialization).

ProcessState: Tracks process state transitions (starting, running, stopped).

Usage Patterns

Pattern 1: Create supervision tree

import { Supervisor, LongRunner, OneShot } from "@copilot-ld/libsupervision";

const supervisor = new Supervisor();
supervisor.add(new OneShot("migrate", "npm run migrate"));
supervisor.add(new LongRunner("web", "npm start"));
await supervisor.start();

Pattern 2: Handle signals

process.on("SIGTERM", async () => {
  await supervisor.stop(); // Graceful shutdown
});

Integration

Powers the service supervision system. Used by librc for service management.