service-manager
Skill2 starsChanged 10 months agoMITView on GitHub
Use when adding background service management to a project that runs dev servers, preview servers, or any long-running processes. Also use when user says "service manager", "background server", "start/stop services", "PID management", "log rotation", or needs Makefile targets for start/stop/status/tail/logs.
- Reads credentials
- Installs packages
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- cendoj-toolkitSkill
- contract-first-clean-archSkill
- drawio-uml-shapesSkill
- expert-panelSkill
- huly-apiSkill
- makefile-service-conventionsSkill
- portless-service-integrationSkill
- repo-kickstartSkill
- validating-skillsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 17
Add background service management to any project with PID tracking, health checks, log rotation, and Makefile integration.
- Very specific: line 65
Every managed service ships the full quartet (start/stop/restart/status, aggregate AND per-service) — see makefile-service-conventions for …
- Very specific: line 74
Add tsx to devDependencies for running TypeScript service manager:
- Very specific: line 86
Use the example file at examples/service-manager.ts as a starting point.
- Very specific: line 101
Document all configurable variables with commented defaults.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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
Service Manager Pattern
Add background service management to any project with PID tracking, health checks, log rotation, and
Makefile integration. Replaces foreground-only make dev patterns with a full
start/stop/status/tail DX.
When to Use
- Project has dev servers that run in foreground and block the terminal
- Need to manage multiple services (dev, preview, etc.) independently
- Want log persistence and rotation for background services
- Need health checks to verify services are actually responding
- Want consistent
make start/stop/status/tailinterface across projects
When NOT to Use
- Single-command scripts that don't need background management
- Docker/container-managed services (use docker-compose instead)
- Projects already using PM2, systemd, or similar process managers
Architecture
project/
├── Makefile # Orchestrates via SM variable
├── .env.example # Documented config options
├── .env.local # User overrides (git-ignored)
├── scripts/
│ └── service-manager.ts # Core manager (TypeScript, runs via tsx)
├── .state/ # PID files (git-ignored)
│ └── <service>.pid # Format: pid:timestamp
└── .logs/ # Log files with rotation (git-ignored)
└── <service>.logQuick Reference
| Command | Effect |
make start | Start the default service set in background |
make start/<svc> | Start one service in background |
make start/<svc>/fg | Start in foreground (Ctrl+C to stop) |
make stop | Stop all services (graceful SIGTERM → SIGKILL) |
make stop/<svc> | Stop one service |
make restart | Stop + start (PRIMARY — always ship with start/stop) |
make restart/<svc> | Restart one service |
make status | Show running/stopped with health check |
make status/<svc> | Status of one service |
make status/details | Add PID, uptime, log size, paths |
Every managed service ships the full quartet (start/stop/restart/status, aggregate AND
per-service) — see makefile-service-conventions for the binding rule; this skill's manager is one
way to implement it. | make tail | tail -f all running service logs | | make logs | List log
files with sizes | | make logs/rotate | Rotate log files |
Implementation Steps
Step 1: Add Dependencies
Add tsx to devDependencies for running TypeScript service manager:
{
"devDependencies": {
"tsx": "^4.0.0"
}
}Step 2: Create scripts/service-manager.ts
Use the example file at examples/service-manager.ts as a starting point. Adapt:
getServices()function — Define your services with:name,displayName— identifier and human labelport,portEnvVar— port number and env var name for overridecwd— working directory for the commandcommand— array of command + args (e.g.,['pnpm', 'dev', '--port', '3000'])healthUrl— HTTP URL for health check (use{port}placeholder)
loadEnv()— reads.env.local(not.envto avoid framework conflicts)- Environment variables — add project-specific config vars at the top
Step 3: Create .env.example
Document all configurable variables with commented defaults. See examples/.env.example.
Step 4: Create/Update Makefile
Key pattern — delegate to service manager via SM variable:
SM := npx tsx scripts/service-manager.ts
# Load optional .env.local
-include .env.local
# Export env vars to service manager
export VAR1 VAR2 PORT1 PORT2
# Defaults
VAR1 ?= default_value
start: _ensure
@$(SM) start <service>
stop:
@$(SM) stop --all
restart: stop start
status:
@$(SM) status
_ensure: node_modules
node_modules: package.json
@pnpm install
@touch node_modulesStep 5: Update .gitignore
.state/
.logs/
.env.localCore Service Manager Features
Kept from example (do not remove):
- PID files — Format
pid:timestampin.state/<service>.pid - Process tree kill —
pgrep -Precursive, SIGTERM then SIGKILL with timeout - Port detection —
lsof -ti tcp:<port>fallback when PID file stale - Health checks — HTTP GET with 2s timeout via
fetch() - Log rotation — Size-based rotation with configurable max files
- Signal handlers — SIGINT/SIGTERM cleanup for foreground mode
- Detached spawn —
detached: true,stdio: ['pipe', logFd, logFd],unref()
Common Adaptations
| Scenario | Change |
| Monorepo (multiple apps) | Add APPS_DIR, use join(APPS_DIR, 'app-name') for cwd |
| Extra env per service | Add env?: Record<string, string> to ServiceConfig |
| Build-then-serve | Use pnpm run preview script that chains build + serve |
| Conditional flags | Build command array dynamically based on env vars |
| Custom health check | Override healthUrl or extend checkHealth() |
Common Mistakes
| Mistake | Fix |
Using .env instead of .env.local | Frameworks read .env — use .env.local to avoid conflicts |
| Not exporting env vars in Makefile | Add export VAR1 VAR2 for service manager to see them |
Missing _ensure prerequisite | All service targets need _ensure (which depends on node_modules) |
Forgetting .gitignore entries | .state/, .logs/, .env.local must be git-ignored |
Using && in spawn command array | Shell operators don't work in spawn — create a npm script instead |
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.

