开发部门有时候需要对写的代码进行错误检测并实时预览,虽然可以通过FTP上传的方式,然而SVN 本身有hooks模块,我们可以通过它实现开发部门的需求。
[root@svn ~]# cat /data/svn/repos/hooks/post-commit
#!/bin/sh
#FileName: post-commit
#Description: Automatic updates to web server code
#Author: shuhui
#Version: v1.0
IP=192.168.198.248
DIR=/data/www/daidaicn.com
DATE=$(date +%F' '%T)
OWER=apache
# Update code
/usr/bin/ssh root@$IP /usr/bin/svn update $DIR --username=admin --password=admin@2015
# Permission set
/usr/bin/ssh root@$IP /bin/chown -R ${OWER}.${OWER} /data/www
# Log
if [ "$?" -eq "0" ];then
echo "svn update successful on $DATE" >> /var/log/svn_hooks.log
exit 0
else
echo "svn update failure on $DATE" >> /var/log/svn_hooks.log
fi
# 现在只要开发部门上传源码就能看到实时更新内容
[root@svn ~]# tail /var/log/svn_hooks.log
……………………………………………………
svn update successful on Mon Apr 27 16:03:33 CST 2015
svn update successful on Mon Apr 27 16:04:03 CST 2015
svn update successful on Mon Apr 27 16:05:52 CST 2015