Skip to content
On this page

ecosystem.config.js文件是pm2的配置文件,用于配置pm2的运行环境

安装

bash
npm install pm2 -g

使用

bash
# 生成基础配置文件
pm2 init simple
# 启动
pm2 start ecosystem.config.js

配置项

javascript
module.exports = {
  apps : [{
    name: 'app', //应用名称
    script: './app.js', //应用入口文件
    instances: 1, //实例数
    autorestart: true, //自动重启
    watch: false, //监听文件变化
    max_memory_restart: '1G', //最大内存限制重启
    env: { //环境变量
      NODE_ENV: 'development'
    },
    env_production: {
      NODE_ENV: 'production' //生产环境
    }
  }],

  deploy : { //部署
    production : { //生产环境
      user : 'SSH_USERNAME', //ssh用户名
      host : 'SSH_HOSTMACHINE', //ssh主机
      ref  : 'origin/master', //git分支
      repo : 'GIT_REPOSITORY', //git仓库
      path : 'DESTINATION_PATH', //目标路径
      'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production' //部署后执行的命令
    }
  }
};

文档

要保持清醒 永远不抱有意外的幻想 凭空的期待最要命