SVN cross-server configuration Post-commit Automatic Update after commit (SVN is not on the same machine as the Web server)

Source: Internet
Author: User
Tags svn update

background: SVN and the web are not on the same server, need SVN submit after the Web site Automatic SVN update update, review the online tutorial, found that some of the details and Permissions section did not mention the cause of cross-server SSH update script failure, Manual execution of Post-commit can be done by


Requirement: The Web server is able to automate the SVN update update site and immediately see the modified Web page effect after the project has been modified and submitted to the SVN server


Idea: when the project commits, it triggers the script inside the Post-commit and writes it to/var/log/svn.log, and the script triggers the Web site update by SSH-free login to the web and then the SVN up.sh script .


Configuration: SVN server One (172.17.8.8) Web test Server (172.17.8.9) two servers are CentOS7.4 (1708)


SVN project version Environment in/svn/project (directory containing DB hooks and other files) Web site path is/var/www/html/project



Need to install software: Both servers need to install Apache Software (Web server nginx also can) and SVN software, my Web test environment for lamp


Both servers are installed Apache (httpd), SVN (subversion), SVNserver needs to install the SVN and Apache Integration Module (MOD_DAV_SVN), Installed as Yum install httpd subversion mod_dav_svn


This does not detail the SVN account and password and permissions debugging, only say Post-commit, scripts, permissions, and log writing and settings




1. Two servers each set up the SYSTEM account as SVN username (Useradd svn), and set the password for SVN user (passwd svn) Note: This step both servers do the same operation


2. Login to the SVN server to do SSH password-free login to Web server operation:


(1) under the SVN server , use SU-SVN (to take-, the description environment variable also switch to SVN below), switch to the SVN user, execute ssh-keygen-t RSA, all the way back to execute, the successful word will generate SHA256 key file

(2) The SVN user's key file is copied to the SVN user SSH directory under the Web server: ssh-copy-id-i/home/svn/.ssh/id_rsa.pub [email protected], after entering the password, prompt copy is successful.

(3) Use SSH login to the Web server: SSH [email protected], enter the password once, try to execute the command again, confirm that can be free of secret login.


3. Modify the Apache startup process user to SVN

Vim/etc/httpd/conf/httpd.conf

Find user and group (about 66 67 rows) Change Apache to Svn,:wq save exit


Modify the permissions of all SVN directories to SVN users, using the-R recursive method

Chown-r SVN:SVN/SVN


4. Go to the project directory, write the Post-commit script and give it permission to execute

Vim/svn/project/hooks/post-commit

The script is as follows:


#!/bin/sh
Repos= "$"
rev= "$"
Logfile=/var/log/svn.log # #这里是为了保存日志并查看是否有报错, there is an error stating that the execution has not been successful, no error stating that the failure to execute, check the permissions, the implementation of the success will have SVN update information
exec 1>> "$LOGFILE"
EXEC 2>&1
Export. UTF-8
/usr/bin/ssh-l svn 172.17.8.9 "/bin/bash/shell/svnup.sh"
Exit 0

Save exit


Give Post-commit executable permissions

chmod 777/svn/project/hooks/post-commit


5. Create a script log and give SVN permissions

Touch/var/log/svn.log

chmod 777/var/log/svn.log

Chown Svn:svn/var/log/svn.log


6. Restart the Apache server to take effect after the modification is complete

Systemctl Restart Httpd.service


At this point, the SVN server configuration is complete

SVN cross-server configuration Post-commit Automatic Update after commit (SVN is not on the same machine as the Web server)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.