Note:
Server operating system: CentOS
Server IP address: 192.168.21.134
SVN installation path:/usr/local/svn
SVN project path:/home/svn
SVN logon account: osyunwei
SVN logon password 123456
Root directory of the Web site:/home/web
Purpose:
When any changes are made to the svn project, the system automatically detects files from svn in real time and synchronizes them to the root directory of the Web site.
Specific operations:
I. Use post-commit in SVN to automatically detect files from svn in real time and synchronize the files to the root directory of the Web site
Cd/home/svn/hooks
Vi post-commit # edit and add the following code
#! /Bin/sh
REPOS = "$1"
REV = "$2"
SVN_PATH =/usr/local/svn/bin
WEB_PATH =/home/web
SVN_USER = osyunwei
SVN_PASS = 123456
WEB_USER = www
LOG_PATH =/tmp/svn. log
Echo 'date "+ % Y-% m-% d % H: % M: % S" '>>$ LOG_PATH
Echo 'whoam', $ REPOS, $ REV> $ LOG_PATH
$ SVN_PATH/svn update $ WEB_PATH -- username $ SVN_USER -- password $ SVN_PASS -- no-auth-cache> $ LOG_PATH
Chown $ WEB_USER. $ WEB_USER-R $ WEB_PATH
: Wq! # Save and exit
Chown www: www/home/svn/hooks/post-commit # set the user group to which the script belongs. www is the web service running account and group.
Chmod + x/home/svn/hooks/post-commit # add the script execution permission
Note:
Whoami # The user who executes the program
REPOS = "$1" # svn project absolute path value
REV = "$2" # Latest version
-- No-auth-cache # Do not save account authentication information
2. Client testing
After a file is added to the svn client, the Web page is displayed in real time! As shown in the following figure: