auto-update can run in git subdirs; review GIT_WHITELIST for daemon
[infrastructure.git] / scripts / git-daemon.init.d
1 #!/bin/bash
2 #
3 # Init file for git daemon
4 #
5 # chkconfig: 2345 55 25
6 # description: git server daemon
7 #
8 # processname: git-daemon
9 # pidfile: /var/run/git.pid
10
11 # source function library
12 . /etc/rc.d/init.d/functions
13
14 # pull in sysconfig settings
15 [ -f /etc/sysconfig/git ] && . /etc/sysconfig/git
16
17 RETVAL=0
18 prog="git-daemon"
19
20 # Some functions to make the below more readable
21 GIT=/usr/bin/git-daemon
22 PID_FILE=/var/run/git-daemon.pid
23
24 # override OPTIONS altogether for more flexibility
25 OPTIONS=${OPTIONS:- --pid-file=${PID_FILE} --base-path=${GITDIR} --port=${PORT} ${VERBOSE} ${DETACH} ${SYSLOG} ${EXPORT} ${GITWHITELIST}}
26
27 runlevel=$(set -- $(runlevel); eval "echo \$$#" )
28
29 start()
30 {
31         echo -n $"Starting $prog: "
32         $GIT $OPTIONS && success || failure
33         RETVAL=$?
34         [ "$RETVAL" = 0 ] && touch /var/lock/subsys/git
35         echo
36 }
37
38 stop()
39 {
40         echo -n $"Stopping $prog: "
41         if [ -n "`pidfileofproc $GIT`" ] ; then
42             killproc $GIT
43         else
44             failure $"Stopping $prog"
45         fi
46         RETVAL=$?
47         # if we are in halt or reboot runlevel kill all running sessions
48         # so the TCP connections are closed cleanly
49         if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then
50             killall $prog 2>/dev/null
51         fi
52         [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/git
53         echo
54 }
55
56 case "$1" in
57         start)
58                 start
59                 ;;
60         stop)
61                 stop
62                 ;;
63         restart)
64                 stop
65                 start
66                 ;;
67         condrestart)
68                 if [ -f /var/lock/subsys/git ] ; then
69                         if [ "$RETVAL" = 0 ] ; then
70                                 stop
71                                 # avoid race
72                                 sleep 3
73                                 start
74                         fi
75                 fi
76                 ;;
77         status)
78                 status -p $PID_FILE git-daemon
79                 RETVAL=$?
80                 ;;
81         *)
82                 echo $"Usage: $0 {start|stop|restart|condrestart|status}"
83                 RETVAL=1
84 esac
85 exit $RETVAL