Build the SVN service project and synchronize the code to the project directory
As the project grows, more people are needed to participate in the development of the same project. SVN is used for multiple people to jointly develop the same project and share resources.
There are two ways to run SVN server: one is as a standalone server, the other is to run with Apache. Both methods have their own advantages and disadvantages, and users can choose for themselves. Here we only discuss the first method: as a standalone server.
Create SVN repository
First we need to install the SVN application. Here we choose the operating system of centos. Installing the SVN application in Linux is actually very simple. Use the following command
# yum install svn
Then the installation process will appear. After the installation is complete, we will create a new SVN repository reptest. For ease of management, we will create a new folder to store all repositories/repos
# mkdir /repos
# svnadmin create /repos/reptest
After the creation is completed, we enter the warehouse and find that there are several files and directories in this directory
# cd /repos/reptest
# ls
conf db format hooks locks README.txt
In this way, we have created an SVN repository.
Configuring User Permissions
After creating the repository, if you want to use it as a standalone server, you must configure user permissions. Here you need to use three files: svnserve.conf, authz, and passwd.
svnserve.conf
Use vim to open the svnserve.conf file and modify the following items.
anon-access = read //remove the leading #
auth-access = write //remove the leading #
password-db = passwd //remove the leading # the default is password, this file can be customized
authz-db = authz //remove the leading # the default is authz, this file can be customized
Save and exit
passwd
The purpose of this file is to set the user and password that can access the service. The users in this file can access the SVN service. Add the following content to this file
[users]
svnuser = svnuser123
After saving and exiting, we set a user svnuser who can access the service, and its password is svnuser123
authz
This file verifies the user's permissions on the corresponding directory. We add the following content at the end of the file
[/]
svnuser = rw
svnuser has read and write permissions for the entire root directory of the SVN service.
After editing the above three files, start using the service.
Start SVN service
Next, we start to start the SVN service. There are two types of services here: one is a single warehouse and the other is multiple warehouses.
Single warehouse
The service for a single repository is actually very simple. Remember the directory /repos we created at the beginning to store the repository? Here we created a new svntest repository in this directory. If it is a single repository, we only need to connect the repository name after /repos when starting the service - /repos/svntest
# svnserve –d –r /repos/svntest
After executing the above command, we will start the SVN service.
For this single warehouse access form, you can use the following command
# svn checkout svn://ip –username svnuser –password svnuser123 /target directory
In this way, what we check out is the contents of the svntest warehouse.
Multiple warehouses
The way to start a service with multiple repositories is actually not much different from the way to start a service with a single repository. The main difference is that we start by creating a new directory /repos to store the repositories. In this way, we don't need to add the directory name when starting the service. Just use /repos
# svnserve –d –r /repos
After the service is enabled, the access method changes
# svn checkout svn://ip/svntest –username svnuser –password svnuser123
When accessing, you need to add the svntest repository name after the svn address.
Of course, if we just want to save the code we developed, we have already completed it here. But sometimes we need to synchronize the code we submitted to the web directory. In this case, we also need to use the SVN hook post-commit to achieve our needs.
Post-commit synchronization code
First, we need to define the directory of our application project. Here we use /web as the directory of our web application project.
Then we go into the /web directory and check out a copy of the code from the repository.
# cd /web
# svn checkout svn://ip/svntest –username svnuser –password svnuser123
//Here we assume that multiple repositories are used
Next, edit the shell script post-commit.
# vim /repos/svntest/hooks/post-commit
Add the following script to the opened post-commit editing interface
#!/bin/bash
export LANG=zh_CN.UTF-8 #File encoding
REPOS="$1" #Warehouse path
REV="$2" #Version number of the code just submitted
SVN=/usr/bin/svn # svn command
WEB=/web/svntest # web directory
LOG=/data/home/auto_svn.log #Log file
$SVN update $WEB --username react --password react123 #Last updated command
Save and exit. Then modify the user permissions for post-commit. Give the user the permission to execute it.
# chmod u+x /repos/svntest/hooks/post-commit
Finally restart the SVN service
# ps –ef | grep svn //First, detect the current process id
root 4888 1 0 Mar25 ? 00:00:00 svnserve -d -r /repos
# kill -9 4888 //4888 is the process id. Use the kill command to kill the process.
# svnserve –d –r /repos //Restart the service
# ps –ef | grep svn
root 17957 1 0 19:38 ? 00:00:00 svnserve -d -r /repos
//The service has been started successfully, and its process id is 17957
At this time, when we submit new or modified code, the code will be automatically synchronized to the /web/svntest directory.
But there is a problem with this, that is, there will be a .svn directory in the /web/svntest directory. This poses a hidden danger to web security. Of course, such a problem can be eliminated through the rewrite function of nginx or apache. We can check the specific implementation by ourselves.
I hope the above simple process of building the SVN service will be helpful to you in your actual work.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
How to use the Linux file remote copy command scp
Publish Date:2025/04/08 Views:151 Category:OPERATING SYSTEM
-
Scp copies files between two hosts over the network, and the data is encrypted during transmission. Its underlying layer uses ssh for data transmission. And it has the same authentication mechanism and the same security level as ssh. When u
Linux server svn remote code synchronization
Publish Date:2025/04/08 Views:79 Category:OPERATING SYSTEM
-
In the article "Building SVN Service Project and Synchronizing Code to Project Directory" , we briefly introduced how to use SVN to synchronize submitted code to the working directory. But there is a problem here, that is, the SVN service a
Nodejs automatically restarts after modifying the code
Publish Date:2025/04/08 Views:93 Category:OPERATING SYSTEM
-
NodeJs can automatically restart after modifying the code, saving us the trouble of ctr+c and then using node. But in terms of time, if the project is already online and running normally, and there are not many modifications, then we can do
Git installation and establishment of local warehouse service
Publish Date:2025/04/05 Views:89 Category:Git
-
Git is a distributed version control system: the client does not only extract the latest version of the file snapshot, but also completely mirrors the original code repository. It has the following advantages: a. Since every extraction oper
Completely delete the Git repository
Publish Date:2025/04/04 Views:137 Category:Git
-
Initializing a git repository using git init or cloning a git repository from GitHub also comes with a .git directory that contains different directories/files related to your project. Deleting a git repository locally sounds like one of th
Update the forked repository
Publish Date:2025/04/04 Views:159 Category:Git
-
Forking Meaning you copied it to your own, but it is marked as forked from the original repository. You can add, edit, and delete files in your version. Your forked repository can be easily fetched from upstream. Update in Git 分叉仓库
Undo commits before pushing to remote repository in Git
Publish Date:2025/04/01 Views:69 Category:Git
-
This article explains how to reset commits in Git that have not yet been pushed to a remote repository. Git is a version control system that we use to track changes made to files in a project directory. In Git, commits are used to track cha
Delete the Git local repository
Publish Date:2025/03/30 Views:54 Category:Git
-
Many software developers use Git to share code with other teams, and to manage source code as a team. Most open source software development is done using Git. Git is free and distributed under the terms of the GNU General Public License, ve
Git lists remote branches
Publish Date:2025/03/30 Views:77 Category:Git
-
This article will show you how to list remote repositories from your local branches. A remote repository is a project hosted on a server, such as Github/Gitlab. git remote Allows us to use short names (aliases) to execute commands instead o