スキル一覧に戻る
octave-commons

pm2-process

by octave-commons

A myth engine

1🍴 0📅 2026年1月25日
GitHubで見るManusで実行

SKILL.md


name: pm2-process description: PM2 process management for Node.js applications in production license: MIT compatibility: opencode metadata: audience: devops runtime: node

What I do

  • Configure PM2 for Node.js application management
  • Set up process files and clustering
  • Monitor logs, metrics, and process health
  • Configure auto-restart strategies and graceful shutdown
  • Deploy applications with zero-downtime
  • Troubleshoot process crashes and performance issues

When to use me

Use me when managing Node.js applications in production, especially when:

  • Running Node.js services on servers
  • Need process clustering and auto-restart
  • Monitoring application health and logs
  • Deploying with minimal downtime
  • Managing environment-specific configurations

Common commands

  • pm2 start app.js - Start application
  • pm2 start ecosystem.config.js - Start with config file
  • pm2 list - List all processes
  • pm2 logs - View logs
  • pm2 monit - Real-time monitoring
  • pm2 reload all - Zero-downtime reload
  • pm2 restart app - Restart process
  • pm2 stop all - Stop all processes
  • pm2 delete all - Remove all processes

Ecosystem configuration

module.exports = {
  apps: [{
    name: 'my-app',
    script: './dist/index.js',
    instances: 'max',
    exec_mode: 'cluster',
    env: {
      NODE_ENV: 'development',
      PORT: 3000
    },
    env_production: {
      NODE_ENV: 'production',
      PORT: 8080
    },
    error_file: './logs/error.log',
    out_file: './logs/out.log',
    log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
    merge_logs: true,
    autorestart: true,
    max_memory_restart: '1G',
    watch: false
  }]
};

Clustering strategies

  • Use instances: 'max' for CPU cores
  • Use instances: 4 for fixed cluster size
  • Enable exec_mode: 'cluster' for multi-instance
  • Sticky sessions: exec_mode: cluster with load balancer

Log management

  • Configure separate error and output logs
  • Rotate logs with pm2 install pm2-logrotate
  • Set log file size limits and retention
  • Use pm2 flush to clear logs
  • Stream logs to external services (e.g., ELK, Datadog)

Monitoring

  • Use pm2 monit for real-time metrics
  • Install pm2-plus for advanced monitoring
  • Set up custom metrics with pmx
  • Monitor CPU, memory, and event loop lag
  • Set up alerts for process crashes

Graceful shutdown

  • Handle SIGTERM signals in application code
  • Close database connections before exit
  • Drain HTTP connections gracefully
  • Use pm2 reload instead of restart for zero downtime
  • Configure kill_timeout and wait_ready

Environment management

  • Separate configs per environment (env_production, env_staging)
  • Load env vars from .env files
  • Use pm2 startup to generate startup script
  • Save process list with pm2 save

Deployment patterns

  • Build before starting (npm run build && pm2 start)
  • Use pm2 deploy with git-based deployment
  • Implement health checks before accepting traffic
  • Rollback with pm2 reload app --update-env

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です