在你的git倉庫根目錄中新建pm2配置文件ecosystem.config.js
,如註釋所示,或者執行pm2 init
初始化文件ecosystem.config.js
。javascript
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 java
pm2 deploy production update
複製代碼
pm2 deploy production revert 1
複製代碼
可查看提交記錄,回滾到想要的版本
pm2 deploy production list
node
pm2 deploy production --force
複製代碼
當你代碼有修改可是不想提交時能夠強制發佈git
Happy coding .. :)github