Robert Escriva

Thoughts on technology and computer science

git-daemon Init Scripts on CentOS 5.2

I operate a CentOS 5.2 using Slice Host and use it for many personal projects. Rather than manually start git-daemon in the event of a server reboot, I wrote this init script to bring up git-daemon on boot.

#!/bin/sh
#
#   Startup/shutdown script for Git Daemon
#
#   Linux chkconfig stuff:
#
#   chkconfig: 345 56 10
#   description: Startup/shutdown script for Git Daemon
#
. /etc/init.d/functions

DAEMON=git-daemon
ARGS='--base-path=/home/git/ --detach --user=git --group=git'

prog=git-daemon

start () {
    echo -n $"Starting $prog: "

    # start daemon
    daemon $DAEMON $ARGS
        RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/git-daemon
    return $RETVAL
}

stop () {
    # stop daemon
    echo -n $"Stopping $prog: "
    killproc $DAEMON
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/git-daemon
}

restart() {
    stop
    start
}

case $1 in
    start)
        start
    ;;
    stop)
        stop
    ;;
    restart)
        restart
    ;;
    status)
        status $DAEMON
        RETVAL=$?
    ;;
    *)

    echo $"Usage: $prog {start|stop|restart|status}"
    exit 3
esac

exit $RETVAL

Some quick notes:

  • It serves all git repos with the file 'git-daemon-export-ok' in /home/git/. To mark a repo as ok for export, create 'git-daemon-export-ok' in the .git folder.
  • It requires the binary git-daemon to be present on the system. Many third-party CentOS repositories provide packages for this.
  • The user and group 'git' must exist for the daemon to drop its privileges when it runs.
  • I make no warranty regarding use of this script. Don't blame me if it crashes or eats your first born son. You have been warned.
  • The structure of the script was extracted from several other init scripts on a CentOS 5 box. I do not recall which ones.

Comments

I've temporarily disabled comments. Firmant (my blog backend) has issues with comments on Python 2.4. The current rewrite of the software will support comments, and at that point, I will re-enable them.

I'd be happy to mimic comments in the form of post updates via email. The address you can reach me at is blog@ the same domain as this website prefixed with a mail..

Copyright © 2008 · Robert Escriva
Unless otherwise specified, all posts and articles are licensed under a Creative Commons Attribution 3.0 U.S. License.
Creative Commons License