Howto: Start Subversion at Boot on Ubuntu

Posted by 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

This entry was posted on Monday, January 15th, 2007 at 11:25 am and is filed under *Nix, How To. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

 

23 Responses to “Howto: Start Subversion at Boot on Ubuntu”

  1. mik Says:

    thanks!
    just what I needed!

  2. Alfonso Reyes Says:

    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.

  3. Miles Thompson Says:

    Just what was needed to finish off the installation of subversion. Thanks.

  4. James Haigh Says:

    Thanks for this, just what I was looking for. Works on Debian Sarge too.

  5. Ola Says:

    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

  6. Michael Heusi Says:

    Thank you. With this, even a beginner like me can install subversion.

  7. jkm Says:

    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.

  8. Colin Says:

    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.

  9. Piero Says:

    Thanks a lot, but please next time you should use “normal” charachters (if possible), so that the code could be easily copied and pasted ^_^

  10. phoenix Says:

    Thanks for the helpful hint :)

  11. Chris Says:

    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?

  12. Brad Says:

    I wonder if this is handled the same (or close) in SUSE?

  13. Infrarotkabine Says:

    Thanks for sharing this guide :-)

  14. Sean O Says:

    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

  15. Scott Says:

    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!!

  16. Ravi Says:

    That was a very crisp to the point solution I was looking for … Thanks a Lot

  17. Keith Lynch Says:

    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

  18. Dinesh Dharme Says:

    Thanks, it was really helpful. There were other scripts but they were little complex

  19. Flashmob Says:

    Thanks! I will recommend this to all my friends.

  20. Jack Says:

    Thanks! You rock.

  21. barleone Says:

    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?

  22. Subversion daemon Init script | assumption of advancement Says:

    [...] 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 [...]

  23. Antonio Says:

    T H A N K S !

Leave a Reply