git daemon init script and config
[infrastructure.git] / scripts / git-daemon.init.d
diff --git a/scripts/git-daemon.init.d b/scripts/git-daemon.init.d
new file mode 100755 (executable)
index 0000000..bc3e64b
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/bash
+#
+# Init file for git daemon
+#
+# chkconfig: 2345 55 25
+# description: git server daemon
+#
+# processname: git-daemon
+# pidfile: /var/run/git.pid
+
+# source function library
+. /etc/rc.d/init.d/functions
+
+# pull in sysconfig settings
+[ -f /etc/sysconfig/git ] && . /etc/sysconfig/git
+
+RETVAL=0
+prog="git-daemon"
+
+# Some functions to make the below more readable
+GIT=/usr/bin/git-daemon
+PID_FILE=/var/run/git-daemon.pid
+
+# override OPTIONS altogether for more flexibility
+OPTIONS=${OPTIONS:- --pid-file=${PID_FILE} --base-path=${GITDIR} --port=${PORT} ${VERBOSE} ${DETACH} ${SYSLOG} ${EXPORT} ${GITWHITELIST}}
+
+runlevel=$(set -- $(runlevel); eval "echo \$$#" )
+
+start()
+{
+       echo -n $"Starting $prog: "
+       $GIT $OPTIONS && success || failure
+       RETVAL=$?
+       [ "$RETVAL" = 0 ] && touch /var/lock/subsys/git
+       echo
+}
+
+stop()
+{
+       echo -n $"Stopping $prog: "
+       if [ -n "`pidfileofproc $GIT`" ] ; then
+           killproc $GIT
+       else
+           failure $"Stopping $prog"
+       fi
+       RETVAL=$?
+       # if we are in halt or reboot runlevel kill all running sessions
+       # so the TCP connections are closed cleanly
+       if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then
+           killall $prog 2>/dev/null
+       fi
+       [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/git
+       echo
+}
+
+case "$1" in
+       start)
+               start
+               ;;
+       stop)
+               stop
+               ;;
+       restart)
+               stop
+               start
+               ;;
+       condrestart)
+               if [ -f /var/lock/subsys/git ] ; then
+                       if [ "$RETVAL" = 0 ] ; then
+                               stop
+                               # avoid race
+                               sleep 3
+                               start
+                       fi
+               fi
+               ;;
+       status)
+               status -p $PID_FILE git-daemon
+               RETVAL=$?
+               ;;
+       *)
+               echo $"Usage: $0 {start|stop|restart|condrestart|status}"
+               RETVAL=1
+esac
+exit $RETVAL