码迷,mamicode.com
首页 > 其他好文 > 详细

node工具之pm2

时间:2019-11-02 12:15:48      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:adl   mat   pps   The   top   between   app   简化   命令   

pm2

PM2是带有内置负载平衡器的Node.js应用程序的生产过程管理器。它使您可以使应用程序永远保持活动状态,无需停机即可重新加载它们,并简化常见的系统管理任务。

安装

npm install pm2 -g

常用命令

  • pm2 start app.js 开启进程
  • pm2 list 所有进程
  • pm2 stop <app_name|id|‘all‘|json_conf> / all 停止
  • pm2 restart <app_name|id|‘all‘|json_conf> 重启
  • pm2 delete <app_name|id|‘all‘|json_conf> 删除
  • pm2 describe <id|app_name> 单一进程
  • pm2 show <id|app_name> 单一进程
  • pm2 monit 监控 cpu 和内存使用情况
  • pm2 reload all 重开进程
  • pm2 logs 日志信息
  • pm2 flush 清理日志信息
  • pm2 reloadLogs
  • pm2 startup 开机自启动
  • pm2 save 保存进程状态
  • pm2 unstartup 取消开机自启动
  • pm2 install 安装模块
  • pm2 update 更新

执行npm命令

pm2 start npm -- start

pm2 start npm --no-automation --name {app name} -- run {script name}

  • (--no-automation)当进程崩溃时,pm2会自动帮你重启
  • (--name)启动的名称
  • (--run)执行的命令

参数

# Specify an app name
--name <app_name>

# Watch and Restart app when files change
--watch

# Set memory threshold for app reload
--max-memory-restart <200MB>

# Specify log file
--log <log_path>

# Pass extra arguments to the script
-- arg1 arg2 arg3

# Delay between automatic restarts
--restart-delay <delay in ms>

# Prefix logs with time
--time

# Do not auto restart app
--no-autorestart

# Specify cron for forced restart
--cron <cron_pattern>

# Attach to application log
--no-daemon

使用配置文件

module.exports = {
  apps : [{
    name: "app",
    script: "./app.js",
    env: {
      NODE_ENV: "development",
    },
    env_production: {
      NODE_ENV: "production",
    }
  }, {
     name: 'worker',
     script: 'worker.js'
  }]
}

Doc

官方网站

node工具之pm2

标签:adl   mat   pps   The   top   between   app   简化   命令   

原文地址:https://www.cnblogs.com/mybilibili/p/11780969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!