debian: new upstream release
[git/debian.git] / debian / git-daemon-sysvinit.git-daemon.init
blobcc98a00badb3794238a77e6caff35292eb68879b
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
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
22 # Exit if the package is not installed
23 [ -e /usr/share/git-core/sysvinit/sentinel ] || exit 0
25 # Read configuration variable file if it is present
26 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
28 GIT_DAEMON_USER=${GIT_DAEMON_USER:-gitdaemon}
29 GIT_DAEMON_BASE_PATH=${GIT_DAEMON_BASE_PATH:-/var/lib}
30 GIT_DAEMON_DIRECTORY=${GIT_DAEMON_DIRECTORY:-/var/lib/git}
32 DAEMON_ARGS="--user=$GIT_DAEMON_USER --pid-file=$PIDFILE --detach"
33 DAEMON_ARGS="$DAEMON_ARGS --reuseaddr --verbose $GIT_DAEMON_OPTIONS"
34 DAEMON_ARGS="$DAEMON_ARGS --base-path=$GIT_DAEMON_BASE_PATH $GIT_DAEMON_DIRECTORY"
36 # Load the VERBOSE setting and other rcS variables
37 . /lib/init/vars.sh
39 # Define LSB log_* functions.
40 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
41 . /lib/lsb/init-functions
44 # Function that starts the daemon/service
46 do_start()
48 # Return
49 # 0 if daemon has been started
50 # 1 if daemon was already running
51 # 2 if daemon could not be started
52 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
53 || return 1
54 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
55 $DAEMON_ARGS \
56 || return 2
60 # Function that stops the daemon/service
62 do_stop()
64 # Return
65 # 0 if daemon has been stopped
66 # 1 if daemon was already stopped
67 # 2 if daemon could not be stopped
68 # other if a failure occurred
69 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
70 RETVAL="$?"
71 [ "$RETVAL" = 2 ] && return 2
72 # Many daemons don't delete their pidfiles when they exit.
73 rm -f $PIDFILE
74 return "$RETVAL"
77 case "$1" in
78 start)
79 if [ $GIT_DAEMON_ENABLE = true ]; then
80 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
81 else
82 [ "$VERBOSE" != no ] && log_warning_msg "$NAME not enabled in /etc/default/$NAME, not starting..."
83 exit 0
86 do_start
87 case "$?" in
88 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
89 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
90 esac
92 stop)
93 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
94 do_stop
95 case "$?" in
96 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
97 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
98 esac
100 status)
101 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
103 restart|force-reload)
104 if [ $GIT_DAEMON_ENABLE != true ]; then
105 [ "$VERBOSE" != no ] && log_warning_msg "$NAME not enabled in /etc/default/$NAME, stopping..."
106 do_stop
107 case "$?" in
108 0|1)
109 log_end_msg 0 ;;
111 log_end_msg 1 ;;
112 esac
113 exit
115 log_daemon_msg "Restarting $DESC" "$NAME"
116 do_stop
117 case "$?" in
118 0|1)
119 do_start
120 case "$?" in
121 0) log_end_msg 0 ;;
122 1) log_end_msg 1 ;; # Old process is still running
123 *) log_end_msg 1 ;; # Failed to start
124 esac
127 # Failed to stop
128 log_end_msg 1
130 esac
133 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
134 exit 3
136 esac