see if this works better for having dh put things in the right places
[debian/git-daemon] / etc / init.d / git-daemon
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          git-daemon
4 # Required-Start:    $network $remote_fs $syslog
5 # Required-Stop:     $network $remote_fs $syslog
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: git-daemon service
9 # Description:       git-daemon is a simple server for git repositories,
10 #                    ideally suited for read-only updates, i.e. pulling from
11 #                    git repositories through the network.
12 ### END INIT INFO
13
14 # PATH should only include /usr/* if it runs after the mountnfs.sh script
15 PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/git-core
16 DESC="git-daemon service"
17 NAME=git-daemon
18 DAEMON=/usr/lib/git-core/$NAME
19 PIDFILE=/var/run/$NAME.pid
20 SCRIPTNAME=/etc/init.d/$NAME
21
22 # Exit if the package is not installed
23 [ -x $DAEMON ] || exit 0
24
25 # Read configuration variable file if it is present
26 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
27
28 GIT_DAEMON_USER=${GIT_DAEMON_USER:-gitdaemon}
29 GIT_DAEMON_DIRECTORY=${GIT_DAEMON_DIRECTORY:-/var/cache/git}
30
31 DAEMON_ARGS="--user=$GIT_DAEMON_USER --reuseaddr --syslog --verbose $GIT_DAEMON_OPTIONS --base-path=$GIT_DAEMON_DIRECTORY $GIT_DAEMON_DIRECTORY"
32
33 # Load the VERBOSE setting and other rcS variables
34 . /lib/init/vars.sh
35
36 # Define LSB log_* functions.
37 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
38 . /lib/lsb/init-functions
39
40 #
41 # Function that starts the daemon/service
42 #
43 do_start()
44 {
45         # Return
46         #   0 if daemon has been started
47         #   1 if daemon was already running
48         #   2 if daemon could not be started
49         start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
50                 || return 1
51         start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile -- \
52                 $DAEMON_ARGS \
53                 || return 2
54 }
55
56 #
57 # Function that stops the daemon/service
58 #
59 do_stop()
60 {
61         # Return
62         #   0 if daemon has been stopped
63         #   1 if daemon was already stopped
64         #   2 if daemon could not be stopped
65         #   other if a failure occurred
66         start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
67         RETVAL="$?"
68         [ "$RETVAL" = 2 ] && return 2
69         # Wait for children to finish too if this is a daemon that forks
70         # and if the daemon is only ever run from this initscript.
71         # If the above conditions are not satisfied then add some other code
72         # that waits for the process to drop all resources that could be
73         # needed by services started subsequently.  A last resort is to
74         # sleep for some time.
75         start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
76         [ "$?" = 2 ] && return 2
77         # Many daemons don't delete their pidfiles when they exit.
78         rm -f $PIDFILE
79         return "$RETVAL"
80 }
81
82 case "$1" in
83   start)
84     if [ $GIT_DAEMON_ENABLE = true ]; then
85         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
86     else
87         [ "$VERBOSE" != no ] && log_warning_msg "$NAME not enabled in /etc/default/$NAME, not starting..."
88         exit 0
89     fi
90
91     do_start
92     case "$?" in
93                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
94                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
95         esac
96   ;;
97   stop)
98         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
99         do_stop
100         case "$?" in
101                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
102                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
103         esac
104         ;;
105   status)
106        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
107        ;;
108   restart|force-reload)
109         log_daemon_msg "Restarting $DESC" "$NAME"
110         do_stop
111         case "$?" in
112           0|1)
113                 do_start
114                 case "$?" in
115                         0) log_end_msg 0 ;;
116                         1) log_end_msg 1 ;; # Old process is still running
117                         *) log_end_msg 1 ;; # Failed to start
118                 esac
119                 ;;
120           *)
121                 # Failed to stop
122                 log_end_msg 1
123                 ;;
124         esac
125         ;;
126   *)
127         echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
128         exit 3
129         ;;
130 esac
131
132 :