no longer build f33
[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 # NOTE. on f14 at least git daemon comes linked with xinetd
12 # however as we had written this for f8, and as I don't feel 
13 # comfy with xinetd on top of chkconfig, 
14 # I turned off xinetd and still use this one on f14 as well
15
16 # source function library
17 . /etc/rc.d/init.d/functions
18
19 # pull in sysconfig settings
20 [ -f /etc/sysconfig/git ] && . /etc/sysconfig/git
21
22 RETVAL=0
23 prog="git-daemon"
24
25 # Some functions to make the below more readable
26 # previous location (f8)
27 #GIT=/usr/bin/git-daemon
28 # for f14
29 GIT=/usr/libexec/git-core/git-daemon
30 PID_FILE=/var/run/git-daemon.pid
31
32 # override OPTIONS altogether for more flexibility
33 OPTIONS=${OPTIONS:- --pid-file=${PID_FILE} --base-path=${GITDIR} --port=${PORT} ${VERBOSE} ${DETACH} ${SYSLOG} ${EXPORT} ${GITWHITELIST}}
34
35 runlevel=$(set -- $(runlevel); eval "echo \$$#" )
36
37 start()
38 {
39         echo -n $"Starting $prog: "
40         $GIT $OPTIONS && success || failure
41         RETVAL=$?
42         [ "$RETVAL" = 0 ] && touch /var/lock/subsys/git
43         echo
44 }
45
46 stop()
47 {
48         echo -n $"Stopping $prog: "
49         if [ -n "`pidfileofproc $GIT`" ] ; then
50             killproc $GIT
51         else
52             failure $"Stopping $prog"
53         fi
54         RETVAL=$?
55         # if we are in halt or reboot runlevel kill all running sessions
56         # so the TCP connections are closed cleanly
57         if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then
58             killall $prog 2>/dev/null
59         fi
60         [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/git
61         echo
62 }
63
64 case "$1" in
65         start)
66                 start
67                 ;;
68         stop)
69                 stop
70                 ;;
71         restart)
72                 stop
73                 start
74                 ;;
75         condrestart)
76                 if [ -f /var/lock/subsys/git ] ; then
77                         if [ "$RETVAL" = 0 ] ; then
78                                 stop
79                                 # avoid race
80                                 sleep 3
81                                 start
82                         fi
83                 fi
84                 ;;
85         status)
86                 status -p $PID_FILE git-daemon
87                 RETVAL=$?
88                 ;;
89         *)
90                 echo $"Usage: $0 {start|stop|restart|condrestart|status}"
91                 RETVAL=1
92 esac
93 exit $RETVAL