svn利用钩子post-commit自动更新到线上测试服务器(测试中未验证)

创建一个新的版本库:

[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

 再建一个工作副本:

[root@centos03 www]# pwd
/alidata/www
[root@centos03 www]# mkdir webtest
[root@centos03 www]# #授权:否则提交会报权限错误!
[root@centos03 www]# chmod -R 777 webtest/

配权限:

[root@centos03 conf]# vi svnserve.conf
[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
[root@centos03 conf]# vi passwd
[users]
# harry = harryssecret
# sally = sallyssecret
svnadmin = 123456
test = 123456
[root@centos03 webtest]# vi /home/svn/webtest/conf/authz
[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
admin = svnadmin
user = test
[/]
@admin = rw
[/webtest]
@admin = rw
* =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

 

[root@centos03 webtest]# ps -ef |grep svn
root      2586     1  0 13:33 ?        00:00:00 svnserve -d -r /home/svn/webtest/
root      2590  2475  0 13:33 pts/0    00:00:00 grep svn

进入该目录后,checkout出一个副本,用于同步上线上服务器的路径:

[root@centos03 www]# svn co svn://192.168.1.72/webtest
svn: URL 'svn://192.168.1.72/webtest' doesn't exist

 

[root@centos03 www]# ls /home/svn/
test  webtest #有两个版本库启动的时候应该是:svnserve -d -r /home/svn/

 

[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

 

[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

[root@centos03 vhosts]# vi webtest.conf
server {
        listen       83;
        server_name  localhost;
        index index.html index.htm index.php;
        root /alidata/www/webtest;
        location ~ .*\.(php|php5)?$
        {
                #fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
                expires 30d;
        }
        location ~ .*\.(js|css)?$
        {
                expires 1h;
        }
       
        include /alidata/server/nginx/conf/rewrite/default.conf;
        access_log  /alidata/log/nginx/access/webtest.log;
}

 

[root@centos03 vhosts]# service nginx reload
Reloading nginx!

 

[root@centos03 hooks]# cp post-commit.tmpl post-commit
[root@centos03 hooks]# which svn
/usr/bin/svn

 

[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 可不要根据需求不同步的排除

[root@centos03 hooks]# chmod +x post-commit

 http://darkyin.blog.51cto.com/6260426/1361132

posted @ 2016-05-05 00:49  bass  阅读(1018)  评论(0编辑  收藏  举报