設定批次執行程式,當網站有更新時,將新的程式push上github後,於瀏覽器開啟網址進行主機端的程式同步更新。
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
設定在同步資料夾時不會詢問帳號密碼,如果同步的git來源為public,可以略過。
cd /www/application
進入應用程式資料夾git remote show origin
檢視同步的git網址* remote origin
Fetch URL: https://github.com/...
Push URL: https://github.com/...
HEAD branch: master
Remote branch:
master tracked
...
https://username:[email protected]/...
格式(網址最前方加上username:password@後面不變)git remote set-url origin https://...
設定使用新的URLsudo git clone https://github.com/lelala/update-git.git /www/update
使用git取得程式sudo chown ec2-user -R /www/update
設定資料夾存取權限vi /www/update/config.json
修改config{
"port": 5678,
"targets": [
{
"name": "application",
"path": "/www/application",
"keeplocal": [ "config.json" ],
"mail": {
"smtpTransportOptions": {
"service": "gmail",
"auth": {
"user": "account@gmail",
"pass": "pwdd"
}
},
"from": "account@gmail",
"to": "reciver@mail"
}
},
{
"name": "application2",
"path": "/www/application2",
"keeplocal": [ "config.json" ],
"mail": {
"smtpTransportOptions": {
"service": "gmail",
"auth": {
"user": "account@gmail",
"pass": "pwdd"
}
},
"from": "account@gmail",
"to": "reciver@mail"
},
"writeTag": true,
"requireVersion": true
}
]
}
,
分隔forever start -w --watchDirectory=/www/update/ /www/update/server.js
背景啟動appsudo vim /etc/rc.d/rc.local
開啟自動執行批次檔forever start -w --watchDirectory=/www/update/ www/update/server.js
開啟主機的對外連線PORT:5678,建議指定特定來源IP,免遭攻擊。 應用程式更新時,新版程式push至github後,呼叫http://主機IP:5678/name進行主機端更新。