Saturday, May 18, 2013

Seagate GoFlex Home NAS - SVN server installation

This comes with a story as well, out of some need, not just technical curiosity :-) I recently gave Ubuntu a shot to see how it compares with Windows for Android development (I might post something about it later), and for Windows I used a local VisualSVN Server - a no brainer SVN server package, very easy to install and maintain. When in Ubuntu I can't use it, well, not as it is. I can obviously set up an SVN server on Ubuntu and point to the same repositories (I've actually managed to access them through running svnserve and svn:// URLs as a start), but having a separate SVN server on GoFlex Home would make me feel better knowing that base copy is on another machine in case my laptop HDD crashes, I would only loose the working copy.


See previous post where we installed ipkg (will use it to install the SVN package) and we setup a system account for HDD storage (will use the same again to store the SVN repositories).

SVN software

bash-3.2# ipkg install svn
Installing svn (1.7.7-1) to root...
package apr-util suggests installing sqlite
package apr-util suggests installing openldap-libs
Installing neon (0.29.6-1) to root...
Successfully terminated.

bash-3.2# svnadmin --version
svnadmin, version 1.7.7 (r1393599)
   compiled Oct 10 2012, 00:19:36

SVN repositories

We will prepare the SVN repositories location (/srv/svn linked to external storage), where you can create a new blank repository (I'll call it test):

bash-3.2# mkdir -p /home/0loop0/srv/svn/
bash-3.2# ln -sv /home/0loop0/srv/svn/ /srv/

bash-3.2# cd /srv/svn
bash-3.2# df -h .
Filesystem            Size  Used Avail Use% Mounted on
/dev/loop0            985M   50M  885M   6% /home/0loop0

bash-3.2# mkdir repos
bash-3.2# cd repos

bash-3.2# svnadmin create test
bash-3.2# svnadmin verify test
* Verified revision 0.

bash-3.2# svn mkdir file:///srv/svn/repos/test/trunk -m "Initial commit"
Committed revision 1.

bash-3.2# svn mkdir file:///srv/svn/repos/test/branches -m "Initial commit"
Committed revision 2.

bash-3.2# svn mkdir file:///srv/svn/repos/test/tags -m "Initial commit"
Committed revision 3.

bash-3.2# svn list -v file:///srv/svn/repos/test/
      3 root                  May 18 21:35 ./
      2 root                  May 18 21:35 branches/
      3 root                  May 18 21:35 tags/
      1 root                  May 18 21:34 trunk/

OR, if you have a dump file from a previous repository, you can restore that instead:
bash-3.2# cd /srv/svn/repos

bash-3.2# svnadmin create android-apps
bash-3.2# svnadmin load android-apps < android-apps.svn-dump

SVN server (http://) - FAIL

Unfortunately, although this is how I saw it setup in the first place (no additional processes, running as a module in Appache HTTP server), I couldn't get this working. After linking the additional config and changing it to correctly point to the modules (change LoadModule from libexec to /opt/libexec/...), the process will die with Segmentation fault.

bash-3.2# ln -sv /opt/etc/apache2/conf.d/mod_dav_svn.conf /etc/httpd/conf.d/
create symbolic link `/etc/httpd/conf.d/mod_dav_svn.conf' to `/opt/etc/apache2/conf.d/mod_dav_svn.conf'

bash-3.2# vi /etc/httpd/conf.d/mod_dav_svn.conf

bash-3.2# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: /bin/bash: line 1:  8741 Segmentation fault      /usr/sbin/httpd

Trying to debug this doesn't show more than maybe an incompatibility between the APR library used to compile Apache HTTP server and the modules...
bash-3.2# apk install gdb

bash-3.2# gdb httpd
GNU gdb 6.8

(gdb) run
Starting program: /usr/sbin/httpd
(no debugging symbols found)
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
[New Thread 0x404d1000 (LWP 7770)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x404d1000 (LWP 7770)]
0x40736034 in apr_pool_create_ex () from /opt/lib/

Fix it back by removing the link, otherwise the webserver will not start next time:

bash-3.2# unlink /etc/httpd/conf.d/mod_dav_svn.conf

bash-3.2# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd:                                            [  OK  ]

SVN server (svn://)

Although not ideal, as it requires a separate process (svnserver) and it will make it harder to setup as we will need to start it with a script to run the external partition is mounted, here we go...

bash-3.2# cd /etc/oe-initscripts/oe-bootfinish/start.d/

bash-3.2# cat > 1_svnserve << EOL
/opt/bin/svnserve -d -r /srv/svn/repos

bash-3.2# cat 1_svnserve
/opt/bin/svnserve -d -M 8 -r /srv/svn/repos

bash-3.2# chmod a+x 1_svnserve

Test the script, see how the SVN server works:

bash-3.2# ./1_svnserve

bash-3.2# svn list -v svn://localhost/test
      3 root                  May 18 21:35 ./
      2 root                  May 18 21:35 branches/
      3 root                  May 18 21:35 tags/
      1 root                  May 18 21:34 trunk/
Let's also create the stop script - remember in previous post we created the unmount script with a "9_" prefix so that we can create the svnserve script with a lower prefix to make it run before it, otherwise the partition will be in use and won't be able to unmount and flush, possibly leading to loss of data or corruption of the SVN repository...
bash-3.2# cd /etc/oe-initscripts/oe-bootfinish/stop.d/

bash-3.2# cat > 8_svnserve << EOL
killall svnserve

bash-3.2# chmod a+x 8_svnserve
Trying the stop script...
bash-3.2# ./8_svnserve

bash-3.2# svn list -v svn://localhost/test
svn: E000111: Unable to connect to a repository at URL 'svn://localhost/test'
svn: E000111: Can't connect to host 'localhost': Connection refused

Finally reboot and try accessing the repository from another machine, using svn://goflex_home/test/ (on Windows) or svn://ip_address/test (on Linux - that's because of the character in the name, nslookup works with "goflex home", but not svn...)

SVN backup

As we've mounted the SVN repositories inside of the file partition, I know I would feel more comfortable to know there is a backup that I can easily access if that gets corrupted. So what we're going to do is to setup a script to run either every night or every two days and make a dump of the repository, and make that available in the \\goflex_home\GoFlex Home Backup directory.
bash-3.2# cd /srv/svn
bash-3.2# cat > svn-backup << EOL

if [ -z "\$1" ]; then
  echo -e "Usage:\n   \$0 repository-name"
  exit 99

OUTPUT_DIR=/home/system/GoFlex\ Home\ Backup/svn
OUTPUT_FILE=\$1.svn-dump-\$(date +"%Y%m%d-%H%M%S")

/opt/bin/svnadmin -M 8 -q dump /srv/svn/repos/\$1 > "\$OUTPUT_DIR/\$OUTPUT_FILE"
/usr/bin/zip -m -2 -j "\$OUTPUT_DIR/\$" "\$OUTPUT_DIR/\$OUTPUT_FILE"

echo -e "\nTrimming backups - older than \$KEEP_DAYS days..."
find "\$OUTPUT_DIR" -name "\$1.*.zip" -mtime +\$KEEP_DAYS -exec ls {} \; -exec rm {} \;

bash-3.2# chmod a+x svn-backup

bash-3.2# cd "/home/system/GoFlex Home Backup/"
bash-3.2# mkdir svn
bash-3.2# cd svn

bash-3.2# /srv/svn/svn-backup test
* Dumped revision 0.
* Dumped revision 1.
* Dumped revision 2.
* Dumped revision 3.
   adding: test.svn-dump-20130518-234455 (deflated 71%)

Trimming backups - older than 31 days...

bash-3.2# ls -la *
total 0
-rwxrwxrwx 1 apache users 320 May 18 22:07

Now that we tested the command line we're going to add it to the cron to run every night at 11pm.
bash-3.2# cat > /etc/cron.d/svn-backup << EOL
0 23 * * * root /srv/svn/svn-backup test

bash-3.2# cat /etc/cron.d/svn-backup
0 23 * * * root /srv/svn/svn-backup test

No comments :

Post a Comment