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