utility to get single_ip right
[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 # previous location (f8)
22 #GIT=/usr/bin/git-daemon
23 # for f14
24 GIT=/usr/libexec/git-core/git-daemon
25 PID_FILE=/var/run/git-daemon.pid
26
27 # override OPTIONS altogether for more flexibility
28 OPTIONS=${OPTIONS:- --pid-file=${PID_FILE} --base-path=${GITDIR} --port=${PORT} ${VERBOSE} ${DETACH} ${SYSLOG} ${EXPORT} ${GITWHITELIST}}
29
30 runlevel=$(set -- $(runlevel); eval "echo \$$#" )
31
32 start()
33 {
34         echo -n $"Starting $prog: "
35         $GIT $OPTIONS && success || failure
36         RETVAL=$?
37         [ "$RETVAL" = 0 ] && touch /var/lock/subsys/git
38         echo
39 }
40
41 stop()
42 {
43         echo -n $"Stopping $prog: "
44         if [ -n "`pidfileofproc $GIT`" ] ; then
45             killproc $GIT
46         else
47             failure $"Stopping $prog"
48         fi
49         RETVAL=$?
50         # if we are in halt or reboot runlevel kill all running sessions
51         # so the TCP connections are closed cleanly
52         if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then
53             killall $prog 2>/dev/null
54         fi
55         [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/git
56         echo
57 }
58
59 case "$1" in
60         start)
61                 start
62                 ;;
63         stop)
64                 stop
65                 ;;
66         restart)
67                 stop
68                 start
69                 ;;
70         condrestart)
71                 if [ -f /var/lock/subsys/git ] ; then
72                         if [ "$RETVAL" = 0 ] ; then
73                                 stop
74                                 # avoid race
75                                 sleep 3
76                                 start
77                         fi
78                 fi
79                 ;;
80         status)
81                 status -p $PID_FILE git-daemon
82                 RETVAL=$?
83                 ;;
84         *)
85                 echo $"Usage: $0 {start|stop|restart|condrestart|status}"
86                 RETVAL=1
87 esac
88 exit $RETVAL