]> git.sur5r.net Git - bacula/bacula/blob - bacula/platforms/debian/bacula-sd.in
Fix bug #1538 Start Scripts return incorrect value
[bacula/bacula] / bacula / platforms / debian / bacula-sd.in
1 #! /bin/sh
2 #
3 # bacula  This shell script takes care of starting and stopping
4 #         the bacula Director daemon on Debian/Ubuntu/Kubuntu 
5 #         systems. 
6 #
7 #   Kern E. Sibbald - 21 March 2008
8 #
9 #  For Bacula release @VERSION@ (@DATE@) -- @DISTNAME@
10 #
11 ### BEGIN INIT INFO
12 # Provides:          bacula-sd
13 # Required-Start:    $network
14 # Required-Stop:     $network
15 # Default-Start:     2 3 4 5
16 # Default-Stop:      0 1 6
17 # Short-Description: Start @BACULA@ Storage daemon at boot time
18 # Description:       Enable @BACULA@ Storage daemon.
19 ### END INIT INFO
20
21
22 NAME="bacula-sd"
23 DESC="@BACULA@ Storage Daemon"
24 DAEMON=@sbindir@/${NAME}
25 BUSER=@sd_user@
26 BGROUP=@sd_group@
27 BOPTIONS="-c @sysconfdir@/${NAME}.conf"
28 BPORT=@sd_port@
29
30 PATH=/sbin:/bin:/usr/sbin:/usr/bin
31
32 test -f $DAEMON || exit 0
33
34 if [ -n "`getent services ${NAME}`" ]; then
35    BPORT=`getent services ${NAME} | awk '{ gsub("/tcp","",$2); print $2; }'`
36 fi
37
38 PIDFILE=@piddir@/${NAME}.${BPORT}.pid
39
40 if [ "x${BUSER}" != "x" ]; then
41    BOPTIONS="${BOPTIONS} -u ${BUSER}"
42 fi
43 if [ "x${BGROUP}" != "x" ]; then
44    BOPTIONS="${BOPTIONS} -g ${BGROUP}"
45 fi
46
47 case "$1" in
48    start)
49       echo -n "Starting ${DESC}: "
50       start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- ${BOPTIONS}
51       RETVAL=$?
52       echo "${NAME}"
53       ;;
54    stop)
55       echo -n "Stopping ${DESC}: "
56       start-stop-daemon --oknodo --stop --quiet --exec ${DAEMON} -- ${BOPTIONS}
57       RETVAL=$?
58       echo "${NAME}"
59       ;;
60    restart|force-reload)
61       $0 stop
62       sleep 5
63       $0 start
64       ;;
65    *)
66       echo "Usage: /etc/init.d/${NAME} {start|stop|restart|force-reload}" >&2
67       exit 1
68       ;;
69 esac
70 exit $RETVAL