Howto: Start Subversion at Boot on Ubuntu
Posted by benrobb on January 15th, 2007
I don’t know if I’ve extolled the virtues of Ubuntu on this blog yet, but they are many. They are, however, not the topic of this post. Every once in a while, I like to try different operating systems on my server, and at the moment, I’m just coming back to an Ubuntu server after a brief fling with Windows Server 2003.
On the list of things to do after install was to get Ubuntu to start the svnserve daemon at boot. I’ve taken the time to look this up enough times that I figured I’d just add it here. This procedure holds for anything you’d like to do at boot, I’m simply running my svn daemon.
Step 1 – Create your script.
Simply create a new file (I called mine svnserve) and type the command you’d like to run
cd /etc/init.d/ # (thanks Alfonso)
sudo touch svnserve
sudo vi svnserve
svnserve -d -r /usr/local/svn/repository_name
Step 2 – Save the script in the /etc/init.d/ folder
Step 3 – Make the script executable
sudo chmod +x svnserve
Step 4 – Add the script to the boot sequence
sudo update-rc.d svnserve defaults
That’s it. When you’re done you should see some output similar to
Adding system startup for /etc/init.d/svnserve ...
/etc/rc0.d/K20svnserve -> ../init.d/svnserve
/etc/rc1.d/K20svnserve -> ../init.d/svnserve
/etc/rc6.d/K20svnserve -> ../init.d/svnserve
/etc/rc2.d/S20svnserve -> ../init.d/svnserve
/etc/rc3.d/S20svnserve -> ../init.d/svnserve
/etc/rc4.d/S20svnserve -> ../init.d/svnserve
/etc/rc5.d/S20svnserve -> ../init.d/svnserve
April 8th, 2007 at 7:00 am
thanks!
just what I needed!
April 14th, 2007 at 7:20 am
Excellent tip!
If I may suggest to add a line before “sudo touch svnserve”, that says:
cd /etc/init.d
Otherwise, “update-rc.d” will not add “svnserve”.
Thanks.
April 18th, 2007 at 12:51 pm
Just what was needed to finish off the installation of subversion. Thanks.
May 3rd, 2007 at 1:13 am
Thanks for this, just what I was looking for. Works on Debian Sarge too.
May 3rd, 2007 at 12:52 pm
Great, thanks!
A contribution, my srartscript:
#!/bin/sh
#
# start/stop subversion daemon.
test -f /usr/bin/svnserve || exit 0
OPTIONS=”-d -r /svnroot”
case “$1″ in
start)
echo -n “Starting subversion daemon:”
echo -n ” svnserve”
start-stop-daemon –start –quiet –oknodo –user svnowner –exec /usr/bin/svnserve — $OPTIONS
echo “.”
;;
stop)
echo -n “Stopping subversion daemon:”
echo -n ” svnserve”
start-stop-daemon –stop –quiet –oknodo –exec /usr/bin/svnserve
echo “.”
;;
reload)
;;
force-reload)
$0 restart
;;
restart)
$0 stop
$0 start
;;
*)
echo “Usage: /etc/init.d/subversion {start|stop|reload|restart}”
exit 1
;;
esac
exit 0
June 25th, 2007 at 1:36 pm
Thank you. With this, even a beginner like me can install subversion.
July 7th, 2007 at 3:51 pm
Thanks for your advanced script, Ola. I’ve only one suggestion:
For changing to user svnowner before starting svnserve you should use –chuid instead of –user. –user only limits killall when stopping to processes running with this uid.
July 8th, 2007 at 11:54 pm
At the risk of sounding repetitious – THANKS.
The Subversion book assumes that we all know how to initiate a daemon at startup. It seems like I’m not the only one that doesn’t.
Ola’s script looks interesting as well, I’ll try that as well soon.
January 7th, 2008 at 1:05 pm
Thanks a lot, but please next time you should use “normal” charachters (if possible), so that the code could be easily copied and pasted ^_^
January 30th, 2008 at 7:19 am
Thanks for the helpful hint
March 19th, 2008 at 9:36 am
Thanks for the great guide.
I’m kind of new to linux, but I didn’t want to run the server as root so I added “sudo -u ” to step 1 line 4 which then became:
sudo -u svnserve -d -r /usr/local/svn/repository_name
I also changed owner both user and group to the file svnserve.
sudo chown : svnserve
What do you think of my suggestions?
June 20th, 2008 at 1:35 pm
I wonder if this is handled the same (or close) in SUSE?
July 25th, 2008 at 10:24 am
Thanks for sharing this guide
July 28th, 2008 at 2:22 pm
The following init script is the head of an example built from the skeleton init script in Ubuntu (/etc/init.d/skeleton) and works for me in Hardy Heron (server edition) just fine. Please note that my repositories are located at “/home/svn,” you may need to modify this.
#! /bin/sh
### BEGIN INIT INFO
# Provides: svnserve
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: SVN initscript
# Description: This file starts the SVN server (svnserve) at boot and should be
# placed in /etc/init.d.
### END INIT INFO
# Author: Sean O’Brien
# Do NOT “set -e”
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESC=”Description of the service”
NAME=svnserve
DAEMON=/usr/bin/$NAME
DAEMON_ARGS=”-d -r /home/svn”
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
July 29th, 2008 at 9:25 am
Just so everyone knows… the characters in the above script that need to be changed are the long dashes to double hypens, and the quotes to simple quotes (not smart quotes). Also note that you can test your script from the command line and make sure all three cases (start, stop, restart, etc) work without rebooting each time.
This script and howto really helps. Thanks to everyone who has posted to this topic!!
January 16th, 2009 at 4:02 am
That was a very crisp to the point solution I was looking for … Thanks a Lot
September 8th, 2009 at 3:33 pm
Found the following worked best on Ubuntu
#!/bin/sh
#
# start/stop subversion daemon.
EXECUTABLE=/usr/bin/svnserve
# Test exist:ence of the executable
test -f $EXECUTABLE || exit 0
# Command line options for starting the service
OPTIONS=’-d -r /var/svnrepos’
case $1 in
start)
echo -n “Starting subversion daemon: $EXECUTABLE $OPTIONS\n”
start-stop-daemon -vo -x $EXECUTABLE -S — $OPTIONS
echo -n “.”
;;
stop)
echo -n “Stopping subversion daemon: $EXECUTABLE $OPTIONS\n”
start-stop-daemon -K -qo -x $EXECUTABLE
echo -n “.”
;;
force-reload)
$0 restart
;;
restart)
$0 stop
$0 start
;;
*)
echo ‘Usage: /etc/init.d/subversion {start|stop|restart}’
exit 1
;;
esac
exit 0
September 21st, 2009 at 1:07 am
Thanks, it was really helpful. There were other scripts but they were little complex
December 9th, 2009 at 7:53 am
Thanks! I will recommend this to all my friends.
December 10th, 2009 at 1:23 pm
Thanks! You rock.
May 7th, 2010 at 5:27 am
Thanks for this simple yet powerfull solution!
I’ve got it working on Ubuntu 10.04 Lucid Lynx.
QUESTION: The other scripts also look interesting. But how to make these working? Where to put them?
July 21st, 2010 at 3:15 am
[...] start-up. So after a little bit searching on the internet and adapting the found resources (here or here), I got my Init script svnserve under [...]
August 3rd, 2011 at 3:34 pm
T H A N K S !