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.