ben robison
when only more words will do
Howto: Start Subversion at Boot on Ubuntu
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
Subscribe to RSS
thanks!
just what I needed!
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.
Just what was needed to finish off the installation of subversion. Thanks.
Thanks for this, just what I was looking for. Works on Debian Sarge too.
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
Thank you. With this, even a beginner like me can install subversion.
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.
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.
Thanks a lot, but please next time you should use “normal” charachters (if possible), so that the code could be easily copied and pasted ^_^
Thanks for the helpful hint
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?
I wonder if this is handled the same (or close) in SUSE?
Thanks for sharing this guide
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
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!!