3 # Bacula(R) - The Network Backup Solution
5 # Copyright (C) 2000-2015 Kern Sibbald
6 # Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
8 # The original author of Bacula is Kern Sibbald, with contributions
9 # from many others, a complete list can be found in the file AUTHORS.
11 # You may use this file and others of this release according to the
12 # license defined in the LICENSE file, which includes the Affero General
13 # Public License, v3.0 ("AGPLv3") and some additional permissions and
14 # terms pursuant to its AGPLv3 Section 7.
16 # This notice must be preserved when any source code is
17 # conveyed and/or propagated.
19 # Bacula(R) is a registered trademark of Kern Sibbald.
21 # bacula-ctl-fd This shell script takes care of starting and stopping
22 # the bacula File daemon.
24 # This is pretty much watered down version of the RedHat script
25 # that works on Solaris as well as Linux, but it won't work everywhere.
27 # description: The Leading Open Source Backup Solution.
34 # On Solaris, you may need to use nawk, or alternatively,
35 # add the GNU binaries to your path, such as /usr/xpg4/bin
39 # All these are not *really* needed but it makes it
40 # easier to "steal" this code for the development
41 # environment where they are different.
55 # A function to stop a program.
60 echo "Usage: killproc {program} {port} [signal]"
65 # check for third arg to be kill level
66 if [ "$3" != "" ] ; then
73 # Get base program name
77 pid=`pidofproc $base $2`
80 if [ "$pid" != "" ] ; then
81 if [ "$notset" = "1" ] ; then
82 if ${PS} -p "$pid">/dev/null 2>&1; then
83 # TERM first, then KILL if not dead
84 kill -TERM $pid 2>/dev/null
86 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
88 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
90 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
91 kill -KILL $pid 2>/dev/null
96 ${PS} -p "$pid" >/dev/null 2>&1
98 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
100 # use specified level only
102 if ${PS} -p "$pid" >/dev/null 2>&1; then
103 kill $killlevel $pid 2>/dev/null
105 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
109 failure "$base shutdown"
111 # Remove pid file if any.
112 if [ "$notset" = "1" ]; then
113 rm -f ${PIDDIR}/$base.$2.pid
118 # A function to find the pid of a program.
123 echo "Usage: pidofproc {program}"
127 # Get base program name
131 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
132 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
133 if [ "$pid" != "" ] ; then
140 if [ -x ${PIDOF} ] ; then
143 if [ "$pid" != "" ] ; then
148 # Finally try to extract it from ps
149 pid=`${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' '`
158 echo "Usage: status {program} {port}"
162 # Get base program name
166 if [ -x ${PIDOF} ] ; then
169 if [ "$pid" != "" ] ; then
170 echo "$base (pid $pid) is running..."
173 pid=`${PSCMD} | ${AWK} 'BEGIN { prog=ARGV[1]; ARGC=1 }
174 { if ((prog == $2) || (("(" prog ")") == $2) ||
175 (("[" prog "]") == $2) ||
176 ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
177 if [ "$pid" != "" ] ; then
178 echo "$base (pid $pid) is running..."
183 # Next try the PID files
184 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
185 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
186 if [ "$pid" != "" ] ; then
187 echo "$base dead but pid file exists"
191 # See if the subsys lock exists
192 if [ -f ${SUBSYSDIR}/$base ] ; then
193 echo "$base dead but subsys locked"
196 echo "$base is stopped"
211 # if /lib/tls exists, force Bacula to use the glibc pthreads instead
212 if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then
213 export LD_ASSUME_KERNEL=2.4.19
218 [ -x ${BACFDBIN}/bacula-fd ] && {
219 echo "Starting the $Bacula File daemon"
221 if [ "${FD_USER}" != '' ]; then
222 OPTIONS="${OPTIONS} -u ${FD_USER}"
225 if [ "${FD_GROUP}" != '' ]; then
226 OPTIONS="${OPTIONS} -g ${FD_GROUP}"
229 if [ "x${VALGRIND_FD}" = "x1" ]; then
230 valgrind --leak-check=full ${BACFDBIN}/bacula-fd $2 $3 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf
232 ${BACFDBIN}/bacula-fd $2 $3 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf
238 # Stop the FD first so that SD will fail jobs and update catalog
239 [ -x ${BACFDBIN}/bacula-fd ] && {
240 echo "Stopping the $Bacula File daemon"
241 killproc ${BACFDBIN}/bacula-fd ${FD_PORT} $2
252 [ -x ${BACFDBIN}/bacula-fd ] && status ${BACFDBIN}/bacula-fd ${FD_PORT}
256 echo "Usage: $0 {start|stop|restart|status}"