Tuesday, February 28, 2012


It becomes very difficult if you have a development team of 30-35 people and all of them are making changes on daily basis and committing the same into SVN. But then the problem is you need to have someone who keeps on updating the SVN whenever there is a need. This results in lot of wasted time. So you can refer to the steps below to setup the POST_COMMIT system such that everytime a developer commits the public_html folder gets updated automatically. 

Let me know in case of any query of problem. 

Create repository:
1. login as root
2. Goto the SVN folder /home/svn/mysvn
3. Run the command: svnadmin create mynewsvn This creates a repository svnadmin create /path/to/repository
4. Run CHMOD and CHOWN commands to make it 775, and user1:user1 (user1 should be in the apache group as well as svn group) 

Auto Update system Setup:
1. Checkout repository wth a user (say user1)
2. Copy update_svn.php to the website's root folder (public_html or htdocs). We have copied this file to production root /home/mysite/public_html
3. Copy the svn_update_step1.sh and svn_update_step2.sh to svn's hooks folder. (/home/svn/mysvn/mynewsvn/hooks)
4. edit update_svn.php. Change the path of svn_update_step1.sh
5. Create key for 'user1'. follow the steps below:
login as 'user1'
ssh-keygen
leave passphrase empty
the keys will be stored in the /home/user1/.ssh folder
cd /home/user1/.ssh
cat id_rsa.pub > id_key_svn
permissions for /home/user1/.ssh folder and files in it should be 600
6. copy the id_rsa file to a location where apache can access it (/home/user1/id_key_svn this is the location because apache is running with USER1)
7. edit svn_update_step1.sh. Change the key path, user name, and location of svn_update_step2.sh
8. edit svn_update_step2.sh. Change the path of hook folder, path of website folder.
9. edit/create the hooks/post-commit file. add the following lines:
#!/bin/sh
10. edit .profile file in /home/velocity folder and add the following lines at the bottom of the file:
ssh-agent bash
ssh-add ~/.ssh/id_rsa


If things don't work,

1. check if the key file works.

ssh -luser1 -i <path_to_key> <host_name>
User should be able to login without and password

2. Open the http://<host_name>update_svn.php. Check the apache error logs
3. login as velocity and run the post-commit/svn_update_step1.sh/svn_update_step2.sh and check the errors



----------------------------------------------------
Filename: .profile


ssh-agent bash
ssh-add ~/.ssh/id_rsa
----------------------------------------------------
Filename: post-commit

#!/bin/sh
wget http://localhost/update_svn.php
----------------------------------------------------
Filename: svn_update_step1.sh

ssh -i /home/user1/id_key_svn user1@localhost /home/svn/mysvn/mynewsvn/hooks/svn_update_step2.sh
----------------------------------------------------
Filename: svn_update_step2.sh

#!/bin/sh
cd /home/svn/mysvn/mynewsvn/hooks
rm -f filelist
rm -f log
echo "user " >> log
whoami >> log
svnlook dirs-changed /home/svn/mysvn/mynewsvn >> /home/svn/mysvn/mynewsvn/hooks/filelist; sed -i -e 's#^#/home/webadmin/public_html/#' /home/svn/mysvn/mynewsvn/hooks/filelist; cat /home/svn/mysvn/mynewsvn/hooks/filelist | xargs /usr/bin/svn up -N >> /home/svn/mysvn/mynewsvn/hooks/log

----------------------------------------------------
Filename: update_svn.php

<?php
$output = shell_exec('/home/svn/mysvn/user1/hooks/svn_update_step1.sh');
echo "<pre>$output</pre>";
?>

----------------------------------------------------

No comments:

Post a Comment