3 # Bacula(R) - The Network Backup Solution
5 # Copyright (C) 2000-2016 Kern Sibbald
7 # The original author of Bacula is Kern Sibbald, with contributions
8 # from many others, a complete list can be found in the file AUTHORS.
10 # You may use this file and others of this release according to the
11 # license defined in the LICENSE file, which includes the Affero General
12 # Public License, v3.0 ("AGPLv3") and some additional permissions and
13 # terms pursuant to its AGPLv3 Section 7.
15 # This notice must be preserved when any source code is
16 # conveyed and/or propagated.
18 # Bacula(R) is a registered trademark of Kern Sibbald.
20 # bacula-ctl-dir This shell script takes care of starting and stopping
21 # the bacula Director daemon
23 # This is pretty much watered down version of the RedHat script
24 # that works on Solaris as well as Linux, but it won't work everywhere.
26 # description: The Leading Open Source Backup Solution.
28 # Copyright (C) 2000-2015 Kern Sibbald
29 # License: BSD 2-Clause; see file LICENSE-FOSS
36 # On Solaris, you may need to use nawk, or alternatively,
37 # add the GNU binaries to your path, such as /usr/xpg4/bin
41 # All these are not *really* needed but it makes it
42 # easier to "steal" this code for the development
43 # environment where they are different.
46 BACDIRCFG=@sysconfdir@
57 # A function to stop a program.
62 echo "Usage: killproc {program} {port} [signal]"
67 # check for third arg to be kill level
68 if [ "$3" != "" ] ; then
75 # Get base program name
79 pid=`pidofproc $base $2`
82 if [ "$pid" != "" ] ; then
83 if [ "$notset" = "1" ] ; then
84 if ${PS} -p "$pid">/dev/null 2>&1; then
85 # TERM first, then KILL if not dead
86 kill -TERM $pid 2>/dev/null
88 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
90 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
92 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
93 kill -KILL $pid 2>/dev/null
98 ${PS} -p "$pid" >/dev/null 2>&1
100 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
102 # use specified level only
104 if ${PS} -p "$pid" >/dev/null 2>&1; then
105 kill $killlevel $pid 2>/dev/null
107 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
111 failure "$base shutdown"
113 # Remove pid file if any.
114 if [ "$notset" = "1" ]; then
115 rm -f ${PIDDIR}/$base.$2.pid
120 # A function to find the pid of a program.
125 echo "Usage: pidofproc {program}"
129 # Get base program name
133 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
134 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
135 if [ "$pid" != "" ] ; then
142 if [ -x ${PIDOF} ] ; then
145 if [ "$pid" != "" ] ; then
150 # Finally try to extract it from ps
151 pid=`${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' '`
160 echo "Usage: status {program} {port}"
164 # Get base program name
168 if [ -x ${PIDOF} ] ; then
171 if [ "$pid" != "" ] ; then
172 echo "$base (pid $pid) is running..."
175 pid=`${PSCMD} | ${AWK} 'BEGIN { prog=ARGV[1]; ARGC=1 }
176 { if ((prog == $2) || (("(" prog ")") == $2) ||
177 (("[" prog "]") == $2) ||
178 ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
179 if [ "$pid" != "" ] ; then
180 echo "$base (pid $pid) is running..."
185 # Next try the PID files
186 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
187 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
188 if [ "$pid" != "" ] ; then
189 echo "$base dead but pid file exists"
193 # See if the subsys lock exists
194 if [ -f ${SUBSYSDIR}/$base ] ; then
195 echo "$base dead but subsys locked"
198 echo "$base is stopped"
213 # if /lib/tls exists, force Bacula to use the glibc pthreads instead
214 if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then
215 export LD_ASSUME_KERNEL=2.4.19
220 [ -x ${BACDIRBIN}/bacula-dir ] && {
221 echo "Starting the $Bacula Director daemon"
223 if [ "${DIR_USER}" != '' ]; then
224 OPTIONS="${OPTIONS} -u ${DIR_USER}"
227 if [ "${DIR_GROUP}" != '' ]; then
228 OPTIONS="${OPTIONS} -g ${DIR_GROUP}"
231 if [ "x${VALGRIND_DIR}" = "x1" ]; then
232 valgrind --leak-check=full ${BACDIRBIN}/bacula-dir $2 $3 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf
234 ${BACDIRBIN}/bacula-dir $2 $3 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf
241 [ -x ${BACDIRBIN}/bacula-dir ] && {
242 echo "Stopping the $Bacula Director daemon"
243 killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT} $2
254 [ -x ${BACDIRBIN}/bacula-dir ] && status ${BACDIRBIN}/bacula-dir ${DIR_PORT}
258 echo "Usage: $0 {start|stop|restart|status}"