
#!/bin/sh echo "$USER" IS_BARE=$(git rev-parse --is-bare-repository) if [ -z "$IS_BARE" ]; then echo >&2 "fatal: post-receive: IS_NOT_BARE" exit 1 fi unset GIT_DIR DeployPath="/Data/www/java_guide" echo "===============================================" cd $DeployPath echo "deploying the test web" #git stash #git pull origin master echo "$USER" expect -c " set timeout 5; spawn git pull; expect { "Username" { send \"username\r\"; exp_continue } "Password" { send \"123456\r\" } }; expect eof; spawn gitbook build; expect "success"; expect eof; " echo "$USER" sleep 10 time=`date` echo "web server pull at webserver at time: $time." echo "================================================" Username for 'http://git.domain.dev': username Password for 'http://[email protected]': Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 372 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) remote: www-data remote: =============================================== remote: deploying the test web remote: www-data remote: spawn git pull remote: Username for 'http://git.domain.dev': username remote: Password for 'http://[email protected]': remote: spawn gitbook build remote: /usr/local/lib/node_modules/gitbook-cli/node_modules/fs-extra/lib/mkdirs/mkdirs-sync.js:41 remote: if (!stat.isDirectory()) throw err0 remote: ^ remote: remote: Error: EEXIST: file already exists, mkdir '/var/www/.gitbook' remote: at Error (native) remote: at Object.fs.mkdirSync (fs.js:794:18) remote: at Object.mkdirsSync (/usr/local/lib/node_modules/gitbook-cli/node_modules/fs-extra/lib/mkdirs/mkdirs-sync.js:22:9) remote: at Object.init (/usr/local/lib/node_modules/gitbook-cli/lib/config.js:21:8) remote: at Object.<anonymous> (/usr/local/lib/node_modules/gitbook-cli/bin/gitbook.js:36:9) remote: at Module._compile (module.js:410:26) remote: at Object.Module._extensions..js (module.js:417:10) remote: at Module.load (module.js:344:32) remote: at Function.Module._load (module.js:301:12) remote: at Function.Module.runMain (module.js:442:10) remote: expect: spawn id exp7 not open remote: while executing remote: "expect eof" remote: www-data remote: web server pull at webserver at time: 2016 年 12 月 28 日 星期三 16:54:08 CST. remote: ================================================ To http://git.domain.dev/java_guide.git b44864b..42e4c63 master -> master pull没有成功,gitbook build也没有成功。sudo -u www-data ./post-receive www-data =============================================== deploying the test web www-data spawn git pull Username for 'http://git.domain.dev': username Password for 'http://[email protected]': remote: Counting objects: 3, done. remote: Compressing objects: 100% (3/3), done. remote: Total 3 (delta 1), reused 0 (delta 0) 展开对象中: 100% (3/3), 完成. 来自 http://git.domain.dev/java_guide b44864b..42e4c63 master -> origin/master 更新 b44864b..42e4c63 warning: 不能访问 '/home/user/.config/git/attributes':权限不够 warning: 不能访问 '/home/user/.config/git/ignore':权限不够 warning: 不能访问 '/home/user/.config/git/attributes':权限不够 Fast-forward warning: 不能访问 '/home/user/.config/git/attributes':权限不够 .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) spawn gitbook build info: 7 plugins are installed info: 6 explicitly listed info: loading plugin "highlight"... OK info: loading plugin "search"... OK info: loading plugin "lunr"... OK info: loading plugin "sharing"... OK info: loading plugin "fontsettings"... OK info: loading plugin "theme-default"... OK info: found 17 pages info: found 1 asset files info: >> generation finished with success in 2.1s ! www-data web server pull at webserver at time: 2016 年 12 月 28 日 星期三 17:02:04 CST. ================================================ pull和gitbook build都成功了。用的 nginx ,版本 1.10.0 ( Ubuntu ),确认了 nginx 的权限是www-data,
Git版本 2.7.4 ,
GitBook 版本 3.2.2 ,
nodejs 版本 4.2.6 ,
npm 版本 3.5.2
1 SpicyCat 2016-12-28 19:08:57 +08:00 从 log 看,你手动执行脚本的时候, git pull 是成功了的。而你用 githook 执行 git pull ,虽然没有报错,但是没有任何输出,你先看看 git pull 有没有成功。 另外,我觉得你这个任务用 githook 做并不合适, 用 CI 做比较合适。或者弄个 crontab 定时任务, 5 分钟刷一次,发现有推送就 build 。 |
2 garsday OP 补充一下,我觉得问题应该在,使用 sudo 调用 www-data 权限的时候,和 nginx 调用 www-data 权限,还是有区别的。 @SpicyCat hook 去执行 git pull ,没有成功。在 hook 里面写脚本,没什么学习成本,而且,这个东西,更新的频率也不高,可能写好了,几个月更新一次,所以,就放在 push 的时候,进行部署,还有 api 文档什么的,基本都是更新频率不高的东西。 |
3 SpicyCat 2016-12-28 22:16:53 +08:00 对 gitbook 不熟啊。那就从错误信息着手吧。 报错说 /var/www/.gitbook 已经存在,看看为啥会报这个错吧。 |