debian/control: new Debian policy version
[debian-git.git] / debian / git-daemon.init
blob0e97c4315d40ea1c732c151fd782bbe97909850d
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/cache}
30 GIT_DAEMON_DIRECTORY=${GIT_DAEMON_DIRECTORY:-/var/cache/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 log_daemon_msg "Restarting $DESC" "$NAME"
105 do_stop
106 case "$?" in
107 0|1)
108 do_start
109 case "$?" in
110 0) log_end_msg 0 ;;
111 1) log_end_msg 1 ;; # Old process is still running
112 *) log_end_msg 1 ;; # Failed to start
113 esac
116 # Failed to stop
117 log_end_msg 1
119 esac
122 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
123 exit 3
125 esac