创建配置项

在你的git仓库根目录中新建pm2配置文件ecosystem.config.js,如注释所示,或者执行pm2 init初始化文件ecosystem.config.js

module.exports = {
  apps : [{
    //pm2名字
    name: "nextcn",
   //pm2运行脚本
    script: "./app.js",
  //环境变量
    env: {
      NODE_ENV: "development",
    },
    env_production: {
      NODE_ENV: "production",
    }
  }],
  deploy: {
    // "production" is the environment name
    production: {
      // 服务器端SSH key 地址, 默认 $HOME/.ssh
      key: "$HOME/.ssh",
      // SSH user 需配置
      user: "root",
      // SSH host 需配置
      host: ["47.98.138.195"],
      // SSH options with no command-line flag, see 'man ssh'
      // can be either a single string or an array of strings
      ssh_options: "StrictHostKeyChecking=no",
      // GIT remote/branch
      ref: "origin/master",
      // GIT ssh远程地址 需配置
      repo: "git@github.com:raoenhui/next-site-cn.git",
      // 放入服务器端地址 需配置
      path: "/ice/pm2",
      // Pre-setup command or path to a script on your local machine
      "pre-setup": "echo 'This is a pre-setup command'",
      // Post-setup commands or path to a script on the host machine
      // eg: placing configurations in the shared dir etc
      "post-setup": "ls -la",
      // pre-deploy action
      "pre-deploy-local": "echo 'This is a pre-deploy-local command'",
      // post-deploy action
      "post-deploy": "npm install && pm2 reload ecosystem.config.js --env production'"
    },
  }
}

安装

pm2 deploy production setup

服务器上的git版本需要在v1.8以上,否则fetch不成功,代码更新不了。可参照CENTOS安装高版本GIT image.png

更新

pm2 deploy production update

回滚

pm2 deploy production revert 1

可查看提交记录,回滚到想要的版本pm2 deploy production list

强制提交

pm2 deploy production --force

当你代码有修改但是不想提交时可以强制发布

参考资料

Happy coding .. :)

Comments评论



也可直接在issue下评论 https://github.com/raoenhui/raoenhui.github.io/issues