您当前的位置: 首页 >  node.js

彭世瑜

暂无认证

  • 2浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Node.js:pm2管理进程启动npm run dev和开机自启

彭世瑜 发布时间:2020-02-28 10:25:13 ,浏览量:2

Node.js Production Process Manager with a built-in Load Balancer.

文档

  • 官网 https://pm2.keymetrics.io/
  • github https://github.com/Unitech/pm2

安装

npm install -g pm2

管理命令

$ pm2 start app.js
$ pm2 start bashscript.sh
$ pm2 start python-app.py --watch

# 启动npm run dev
$ pm2 start npm --watch  -- run dev

pm2 [list|ls|status]   # 显示状态

pm2 logs               # 查看所有进程日志

pm2 monit              # 监控信息

pm2 stop all           # 停止所有进程
pm2 restart all        # 重启所有进程

pm2 stop 0             # 停止进程
pm2 restart 0          # 重启进程
pm2 delete 0           # 删除进程


# 添加额外参数到脚本
-- arg1 arg2 arg3

# eg: pm2启动 npm run start
pm2 start npm --name www -- run start
日志查看

默认日志路径

/root/.pm2/logs/
开机自启
sudo pm2 start xxxx  #启动服务
 
sudo pm2 save # 保存服务
 
sudo pm2 startup # 把已启动服务加到systemd中
 
sudo pm2 unstartup systemd # 删除自动启动服务
使用配置文件
# 生成一份默认的配置文件
pm2 init simple

ecosystem.config.js

module.exports = {
  apps : [{
    name   : "app",
    script : "./app.js"
  }]
}
# Start all applications
pm2 start ecosystem.config.js

参考: https://pm2.keymetrics.io/docs/usage/quick-start/ pm2开机自启动

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.2621s