Create configuration item
Create a new pm2 configuration file ecosystem.config.js in the root directory of your git warehouse, as shown in the comments, or execute the pm2 init initialization file ecosystem.config.js.
module.exports = { apps : [{ //pm2 name name: "nextcn", //pm2 run script script: "./app.js", //environment variable env: { NODE_ENV: "development", }, env_production: { NODE_ENV: "production", } }], deploy: { // "production" is the environment name production: { // Server SSH key address, default $HOME/.ssh key: "$HOME/.ssh", // SSH user needs to be configured user: "root", // SSH host needs to be configured 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 Remote address needs to be configured repo: "git@github.com:raoenhui/next-site-cn.git", // The server address needs to be configured 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'" }, } }
install
pm2 deploy production setup
The git version on the server needs to be above v1.8, otherwise the fetch is not successful and the code cannot be updated. Referable CENTOS install higher version GIT
To update
pm2 deploy production update
RollBACK
pm2 deploy production revert 1
You can view the submission records and roll back to the desired version pm2 deploy production list
Compulsory submission
pm2 deploy production --force
When your code is modified but you don't want to submit it, you can force it to be published
Reference material
Happy coding .. :)