设置启动脚本
服务器启动/重新启动时管理的进程重新启动 PM2
npm install pm2@latest -g
# or
yarn global add pm2
pm2 restart app_name/id
pm2 reload app_name/id
pm2 stop app_name/id
pm2 delete app_name/id
# List
pm2 ls/list/status
pm2 list --sort [name|id|pid|memory|cpu|status|uptime][:asc|desc]
module.exports = {
apps : [
{
name : 'yers',
description : 'yer server',
script : 'src/index.js',
cwd : './projects/yer/service/',
watch : false,
error_file : './logs/err.log',
out_file : './logs/out.log',
args : '--port=8888',
max_memory_restart : '500M',
log_date_format : 'YYYY-MM-DD HH:mm Z'
}
]
};
pm2 ecosystem
pm2 start ecosystem.config.js --only api-app
pm2 logs
pm2 logs app_name/id
pm2 logs --lines 200
# 清空日志
pm2 flush
pm2 flush app_name/id
pm2 install pm2-logrotate
pm2 startup
pm2 save
# 手动恢复进程
pm2 resurrect
sudo npm install pm2@latest -g
pm2 update
pm2 unstartup
pm2 startup
module.exports = {
script: "serve",
env: {
PM2_SERVE_PATH: '.',
PM2_SERVE_PORT: 8080,
PM2_SERVE_SPA: 'true',
PM2_SERVE_HOMEPAGE: './index.html'
}
}
pm2 set pm2:sysmonit true
export PATH=$HOME/frontend/sources/node-v16.14.2-linux-x64/bin:$PATH:$HOME/.local/bin:$HOME/bin