A subversion init.d script for Ubuntu Linux
There are hundreds of guides out there to get svn running in tandem with Apache. However, if, like me, you want to use the svnserve program so subversion isn’t tied to Apache services, then this is for you.
Here’s a cheat sheet/script for creating a new subversion repo:
sudo apt-get install subversion svnadmin create /svn/newRepo groupadd subversion chown -R root:subversion /svn/newRepo chmod -R ug+rw /svn/newRepo
The above repo is now available to any users in the subversion group (add them via /etc/group). You can check out the repo using
svn co svn+ssh://myserver.com/svn/newRepo
(assuming your user has ssh access to the box and is in the group “subversion”).
If you want anonymous access, you need to run svnserve. Unfortunately no init.d script is distributed with it on Ubuntu (or anywhere else I know of), so it’s non-trivial to run it as a daemon. You can hook it into xinetd, but I can never get xinetd working.
So here’s a regular init.d script I wrote (the latest version has lots of contributions from commenters). Nothing fancy; it just runs the command svnserve -d, and then runs it through the kill command to shut it down.
You can run it as user subversion (create with “adduser subversion”) or you can just run it as root. Just change the SVN_USER and SVN_GROUP variables (thanks Andrew!)
#!/bin/sh -e
#
# svnserve - brings up the svn server so anonymous users
# can access svn
#
# Get LSB functions
. /lib/lsb/init-functions
. /etc/default/rcS
SVNSERVE=/usr/bin/svnserve
SVN_USER=subversion
SVN_GROUP=subversion
SVN_REPO_PATH=/home/$SVN_USER/
# Check that the package is still installed
[ -x $SVNSERVE ] || exit 0;
case "$1" in
start)
log_begin_msg "Starting svnserve..."
umask 002
if start-stop-daemon --start
--chuid $SVN_USER:$SVN_GROUP
--exec $SVNSERVE
-- -d -r $SVN_REPO_PATH; then
log_end_msg 0
else
log_end_msg $?
fi
;;
stop)
log_begin_msg "Stopping svnserve..."
if start-stop-daemon --stop --exec $SVNSERVE; then
log_end_msg 0
else
log_end_msg $?
fi
;;
restart|force-reload)
"$0" stop && "$0" start
;;
*)
echo "Usage: /etc/init.d/svnserve {start|stop|restart|force-reload}"
exit 1
;;
esac
exit 0
Save it as /etc/init.d/svnserve, and start it with
/etc/init.d/svnserve start
Add it to start every time you boot:
update-rc.d svnserve defaults
