pm2
Skill4 starsChanged 9 months agoMITView on GitHub
Process management with PM2 — start, stop, restart, monitor long-running processes. Use when: keeping services alive, auto-restart on crash, managing daemon processes, ecosystem configs, log management, startup scripts, process monitoring. Triggers: pm2, process manager, keep alive, daemon, auto-restart, ecosystem config, process monitoring.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- delorenj/skillstheir own version, first seen Nov 7, 2026
- jholhewres/devclaw-skillstheir own version, first seen Oct 9, 2026
- ElvitaStudio/vps-deploy-skillstheir own version, first seen Jun 7, 2026
- TheKREATORS/my-claude-skillstheir own version, first seen Mar 19, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- delorenj/skills★ 17same name
- jholhewres/devclaw-skills★ 4same name
- ElvitaStudio/vps-deploy-skills★ 1same name
- TheKREATORS/my-claude-skills★ 1same 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 repository7 other files it gives its agents.
- azcliSkill
- gcloudSkill
- pre-releaseSkill
- repo-hygieneSkill
- sheet-modelSkill
- vhsSkill
- web-searchSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
1
Distinctive
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 14
Use for long-running services, persistent agents, background workers.
- Very specific: line 140
After pm2 startup, run the command it outputs (may need admin/sudo).
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PM2 — Process Manager
PM2 keeps processes alive, restarts them on crash, and provides monitoring/logging. Use for long-running services, persistent agents, background workers.
Not for detached terminals — use holdpty when you need PTY output, attach/view, or interactive sessions. Not for ephemeral tasks — use
pi -p > file &for quick fire-and-forget agent runs.
Quick Reference
Start a process
# Simple
pm2 start server.js --name myapp
# With interpreter
pm2 start script.py --interpreter python3 --name worker
# With arguments (use -- to separate pm2 args from script args)
pm2 start app.js --name api -- --port 3000 --env production
# From ecosystem file
pm2 start ecosystem.config.cjsManage processes
pm2 list # List all processes (table)
pm2 jlist # List as JSON (for scripting)
pm2 info <name|id> # Detailed process info
pm2 restart <name|id|all> # Restart
pm2 stop <name|id|all> # Stop (keeps in list)
pm2 delete <name|id|all> # Stop + remove from list
pm2 restart <name> --update-env # Restart with refreshed env varsLogs
pm2 logs # Tail all logs
pm2 logs <name> --lines 50 # Tail specific process, last 50 lines
pm2 flush # Clear all log filesLog files location: ~/.pm2/logs/<name>-out.log and <name>-error.log.
Monitoring
pm2 monit # Real-time TUI: CPU, memory, logs
pm2 dash # Dashboard with monitoring + logsEcosystem Config
For reproducible multi-process setups, use an ecosystem.config.cjs file:
// ecosystem.config.cjs
module.exports = {
apps: [
{
name: "api",
script: "dist/server.js",
instances: 2, // cluster mode
exec_mode: "cluster",
env: {
NODE_ENV: "production",
PORT: 3000,
},
max_memory_restart: "500M",
log_date_format: "YYYY-MM-DD HH:mm:ss",
},
{
name: "worker",
script: "dist/worker.js",
autorestart: true,
max_restarts: 10,
restart_delay: 5000,
exp_backoff_restart_delay: 100, // exponential backoff
watch: false,
},
],
};pm2 start ecosystem.config.cjs # Start all apps
pm2 start ecosystem.config.cjs --only api # Start specific app
pm2 restart ecosystem.config.cjs # Restart all
pm2 delete ecosystem.config.cjs # Stop + remove allUseful ecosystem options
| Option | Type | Description |
script | string | Script to run (required) |
interpreter | string | Override interpreter (default: node) |
args | string or string[] | Script arguments |
cwd | string | Working directory |
instances | number | Number of instances (cluster mode) |
exec_mode | string | "fork" (default) or "cluster" |
autorestart | boolean | Auto-restart on exit (default: true) |
max_restarts | number | Max consecutive restarts before stopping |
restart_delay | number | Delay between restarts (ms) |
exp_backoff_restart_delay | number | Exponential backoff base (ms) |
max_memory_restart | string | Restart if memory exceeds (e.g. "500M") |
cron_restart | string | Cron-based restart schedule |
watch | boolean or string[] | Watch for file changes |
ignore_watch | string[] | Paths to ignore when watching |
env | object | Environment variables |
log_date_format | string | Timestamp format for logs |
error_file | string | Custom stderr log path |
out_file | string | Custom stdout log path |
merge_logs | boolean | Merge cluster instance logs |
stop_exit_codes | number[] | Exit codes that skip auto-restart |
Persistence
pm2 save # Save current process list
pm2 resurrect # Restore saved process list
pm2 startup # Generate OS startup script (auto-start on boot)
pm2 unstartup # Remove startup scriptAfter pm2 startup, run the command it outputs (may need admin/sudo).
Then pm2 save to snapshot current processes — they'll auto-start on reboot.
Windows Gotchas
.cmd wrapper resolution
PM2 tries to run .cmd files as Node.js scripts. Never start a .cmd shim directly with PM2.
# ❌ WRONG — resolves to pi.cmd, crashes
pm2 start pi -- -p "prompt"
# ✅ CORRECT — point to the actual .js entry point
pm2 start /path/to/cli.js --interpreter node -- -p "prompt"For npm-installed CLIs, find the real script:
# Find where the .cmd shim points
cat "$(which pi)" | head -5
# → Look for the .js path, then use that with --interpreter nodeIn ecosystem configs, always use the resolved .js path:
module.exports = {
apps: [{
name: "my-agent",
// Resolve the actual cli.js, not the .cmd wrapper
script: "C:\\path\\to\\node_modules\\package\\dist\\cli.js",
interpreter: "node",
args: ["--mode", "json"],
}],
};Log paths
PM2 stores logs at ~/.pm2/logs/. On Windows this is typically C:\Users\<user>\.pm2\logs\.
Daemon
PM2 daemon runs as a background Node.js process. pm2 kill stops the daemon and all managed processes. pm2 ping checks if the daemon is running.
Agent Patterns
Launch a pi agent as a persistent service
First, find the actual cli.js path (see Windows Gotchas above):
# Find pi's real entry point
cat "$(which pi)" | head -5
# e.g. → /path/to/node_modules/@mariozechner/pi-coding-agent/dist/cli.js// ecosystem.config.cjs
module.exports = {
apps: [{
name: "my-agent",
// Use the resolved cli.js path — NOT the .cmd wrapper
script: "/path/to/node_modules/@mariozechner/pi-coding-agent/dist/cli.js",
interpreter: "node",
args: ["--mode", "json", "--cwd", "/path/to/project"],
autorestart: true,
max_restarts: 10,
restart_delay: 5000,
}],
};Note:
pi -pto non-TTY only outputs final text. Use--mode jsonfor full event streaming to PM2 logs.
Check process health from an agent
# Structured output for parsing
pm2 jlist | node -e "
const d = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
d.forEach(p => console.log(p.name, p.pm2_env.status, 'restarts:', p.pm2_env.restart_time));
"Rotate logs
pm2 install pm2-logrotate # Install log rotation module
pm2 set pm2-logrotate:max_size 10M
pm2 set pm2-logrotate:retain 5When NOT to Use PM2
- Detached terminal sessions → use holdpty (PTY output, attach/view)
- Ephemeral agent runs → use
pi -p > file &(fire-and-forget with output capture) - Containers → the container runtime manages lifecycle; PM2 inside Docker is usually redundant
- Systemd environments → use systemd service units natively on Linux
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.

