| name | server-management |
| description | Server management procedures including PM2, monitoring, and log management. CRITICAL for production operations. |
Server Management
PM2 Commands
Process Management
pm2 start ecosystem.config.js
pm2 list
pm2 reload app-name
pm2 stop app-name
pm2 delete app-name
Monitoring
pm2 monit
pm2 show app-name
pm2 logs app-name --lines 100
pm2 logs app-name --err
Cluster Mode
pm2 scale app-name 4
pm2 start app.js -i max
Ecosystem Config
module.exports = {
apps: [{
name: 'app-name',
script: './dist/index.js',
instances: 'max',
exec_mode: 'cluster',
env: {
NODE_ENV: 'production'
},
max_memory_restart: '500M',
log_date_format: 'YYYY-MM-DD HH:mm:ss'
}]
};
Log Management
pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 10M
pm2 set pm2-logrotate:retain 7
Health Checks
curl http://localhost:3000/health
pm2 list | grep -E "online|stopped|errored"
Persistence
pm2 save
pm2 startup
pm2 resurrect