一键导入
pm2
PM2 — process manager for long-running training jobs on remote servers. ecosystem.config.js, common commands, and SSH workflow with uv.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
PM2 — process manager for long-running training jobs on remote servers. ecosystem.config.js, common commands, and SSH workflow with uv.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
pre-commit — git hook framework for automating ruff, pyright, pytest, and other checks before every commit
Pyright static type checker — configuration, common errors, type annotation patterns for Python 3.10+ with uv projects
pytest — test structure, fixtures, markers, parametrize, conftest, and pytest-watch for automated testing in uv projects
Ruff — fast Python linter and formatter replacing flake8, black, isort. Configuration, rule selection, and common fixes.
uv — Python package manager, dependency management, virtual environments, and script running. Replaces pip, pip-tools, virtualenv, pyenv.
| name | pm2 |
| description | PM2 — process manager for long-running training jobs on remote servers. ecosystem.config.js, common commands, and SSH workflow with uv. |
# Via npm (requires Node.js)
npm install -g pm2
# Via NVM (no sudo needed)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts && npm install -g pm2
// ecosystem.config.js — at project root
module.exports = {
apps: [{
name: "stgraph-train",
cwd: "/home/user/fraud-detection-blockchain",
script: "uv",
args: "run python -m stgraph_fs.cli train --config configs/train.yaml",
autorestart: false, // CRITICAL: prevents infinite restart loop after job ends
watch: false,
max_restarts: 0,
time: true, // prefix logs with timestamp
env: {
CUDA_VISIBLE_DEVICES: "0",
}
}]
};
CRITICAL: Always set autorestart: false. PM2 restarts processes by default — a training job that finishes will loop forever without this.
# From ecosystem.config.js (preferred)
pm2 start ecosystem.config.js
# Inline (quick, no config file)
pm2 start --name stgraph-train --no-autorestart --cwd /path/to/repo -- \
uv run python -m stgraph_fs.cli train --config configs/train.yaml
# Specific app from ecosystem file
pm2 start ecosystem.config.js --only stgraph-train
pm2 ls # list all processes + status
pm2 status # same as ls
pm2 logs stgraph-train # stream logs (Ctrl+C to exit)
pm2 logs stgraph-train --lines 200 # last 200 lines
pm2 logs --err # stderr only
pm2 monit # TUI dashboard (CPU, mem, logs)
pm2 stop stgraph-train # stop (keeps in list)
pm2 restart stgraph-train # restart
pm2 delete stgraph-train # stop + remove from list
pm2 kill # stop all processes + daemon
# 1. Local: commit and push
git add . && git commit -m "..." && git push
# 2. SSH into server
ssh user@server
# 3. Pull + sync deps
cd /path/to/repo
git pull && uv sync
# 4. Smoke test (fast dev run)
uv run python -m stgraph_fs.cli train --fast_dev_run
# 5. Launch via PM2
pm2 start ecosystem.config.js
# 6. Verify started, then disconnect
pm2 ls
exit # job continues running
# Default log path
~/.pm2/logs/<app-name>-out.log # stdout
~/.pm2/logs/<app-name>-error.log # stderr
# Custom log path in ecosystem.config.js
{
out_file: "./logs/train-out.log",
error_file: "./logs/train-err.log",
merge_logs: true,
}
pm2 save # save current process list
pm2 startup # generates systemd command (run it as shown)
autorestart: false will cause a completed training job to restart in an infinite loop, overwriting outputs/.pm2 logs streams in real time; use --lines N to see recent history without streaming.nohup or screen.pm2 kill stops the daemon entirely — all jobs stop. Use pm2 stop for individual jobs.