svn利用钩子post-commit自动更新到线上测试服务器(测试中未验证)
创建一个新的版本库:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | [root@centos03 svn] # pwd /home/svn [root@centos03 svn] # svnadmin create webtest [root@centos03 svn] # tree webtest/ webtest/ ├── conf │ ├── authz │ ├── passwd │ └── svnserve.conf ├── db │ ├── current │ ├── format │ ├── fsfs.conf │ ├── fs- type │ ├── min-unpacked-rev │ ├── rep-cache.db │ ├── revprops │ │ └── 0 │ │ └── 0 │ ├── revs │ │ └── 0 │ │ └── 0 │ ├── transactions │ ├── txn-current │ ├── txn-current-lock │ ├── txn-protorevs │ ├── uuid │ └── write-lock ├── format ├── hooks │ ├── post-commit.tmpl │ ├── post-lock.tmpl │ ├── post-revprop-change.tmpl │ ├── post-unlock.tmpl │ ├── pre-commit.tmpl │ ├── pre-lock.tmpl │ ├── pre-revprop-change.tmpl │ ├── pre-unlock.tmpl │ └── start-commit.tmpl ├── locks │ ├── db.lock │ └── db-logs.lock └── README.txt 10 directories, 28 files |
再建一个工作副本:
1 2 3 4 5 | [root@centos03 www] # pwd /alidata/www [root@centos03 www] # mkdir webtest [root@centos03 www] # #授权:否则提交会报权限错误! [root@centos03 www] # chmod -R 777 webtest/ |
配权限:
1 2 3 4 5 6 7 8 | [root@centos03 conf] # vi svnserve.conf<br>[general] ### These options control access to the repository for unauthenticated ### and authenticated users. Valid values are "write", "read", ### and "none". The sample settings below are the defaults. anon-access = read auth-access = write password-db = /home/svn/webtest/conf/passwd authz-db = /home/svn/webtest/conf/authz <br>[root@centos03 conf] # vi passwd <br>[users]<br># harry = harryssecret<br># sally = sallyssecret<br>svnadmin = 123456<br>test = 123456<br>[root@centos03 webtest]# vi /home/svn/webtest/conf/authz <br>[groups]<br># harry_and_sally = harry,sally<br># harry_sally_and_joe = harry,sally,&joe<br>admin = svnadmin<br>user = test<br>[/]<br>@admin = rw<br>[/webtest]<br>@admin = rw<br>* =<br># [repository:/baz/fuz]<br># @harry_and_sally = rw<br># * = r<br> |
1 | [root@centos03 webtest] # ps -ef |grep svn<br>root 2586 1 0 13:33 ? 00:00:00 svnserve -d -r /home/svn/webtest/<br>root 2590 2475 0 13:33 pts/0 00:00:00 grep svn |
进入该目录后,checkout出一个副本,用于同步上线上服务器的路径:
1 2 | [root@centos03 www] # svn co svn://192.168.1.72/webtest svn: URL 'svn://192.168.1.72/webtest' doesn't exist |
1 2 | [root@centos03 www] # ls /home/svn/ test webtest #有两个版本库启动的时候应该是:svnserve -d -r /home/svn/ |
1 2 3 | [root@centos03 www] # ps -ef|grep svn root 2650 1 0 14:00 ? 00:00:00 svnserve -d -r /home/svn/ root 2678 2475 0 14:04 pts /0 00:00:00 grep svn |
1 2 3 4 | [root@centos03 www] # svn co svn://192.168.1.72/webtest Checked out revision 0. [root@centos03 www] # ls phpwind sx webtest xxzz |
配WEB:
我这里是开一个nginx vhost
1 | [root@centos03 vhosts] # vi webtest.conf<br>server {<br> listen 83;<br> server_name localhost;<br> index index.html index.htm index.php;<br> root /alidata/www/webtest;<br> location ~ .*\.(php|php5)?$<br> {<br> #fastcgi_pass unix:/tmp/php-cgi.sock;<br> fastcgi_pass 127.0.0.1:9000;<br> fastcgi_index index.php;<br> include fastcgi.conf;<br> }<br> location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$<br> {<br> expires 30d;<br> }<br> location ~ .*\.(js|css)?$<br> {<br> expires 1h;<br> }<br> <br> include /alidata/server/nginx/conf/rewrite/default.conf;<br> access_log /alidata/log/nginx/access/webtest.log;<br>}<br> |
1 2 | [root@centos03 vhosts] # service nginx reload Reloading nginx! |
1 | [root@centos03 hooks] # cp post-commit.tmpl post-commit<br>[root@centos03 hooks]# which svn<br>/usr/bin/svn<br><br> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | [root@centos03 hooks] # vi post-commit [root@centos03 hooks] # pwd /home/svn/webtest/hooks REPOS= "$1" REV= "$2" SVN= /usr/bin/svn WEB= /alidata/www/webtest RSYNC= /usr/bin/rsync LOG= /tmp/rsync_web .log WEBIP=192.168.1.73 #这是线上web服务器IP export LANG=en_US.UTF-8 $SVN update $WEB --username svnadmin --password 123456 if [ $? == 0 ] echo "" >>$LOG echo ` date ` >> $LOG echo "#####################" >>$LOG $RSYNC -vaztpH --timeout=90 --exclude-from= /home/svn/webtest/exclude .list $web root@$WEBIP: /www/ >>$LOG if #--exclude-from 可不要根据需求不同步的排除 <br>[root@centos03 hooks] # chmod +x post-commit |
http://darkyin.blog.51cto.com/6260426/1361132
联系方式QQ:326528263 EMAIL:clnking@163.com 网名:bass 分享技术 突破难点 创新思维
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步