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-fd This shell script takes care of starting and stopping
21 # the bacula File 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.
33 # On Solaris, you may need to use nawk, or alternatively,
34 # add the GNU binaries to your path, such as /usr/xpg4/bin
38 # All these are not *really* needed but it makes it
39 # easier to "steal" this code for the development
40 # environment where they are different.
54 # A function to stop a program.
59 echo "Usage: killproc {program} {port} [signal]"
64 # check for third arg to be kill level
65 if [ "$3" != "" ] ; then
72 # Get base program name
76 pid=`pidofproc $base $2`
79 if [ "$pid" != "" ] ; then
80 if [ "$notset" = "1" ] ; then
81 if ${PS} -p "$pid">/dev/null 2>&1; then
82 # TERM first, then KILL if not dead
83 kill -TERM $pid 2>/dev/null
85 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
87 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
89 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
90 kill -KILL $pid 2>/dev/null
95 ${PS} -p "$pid" >/dev/null 2>&1
97 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
99 # use specified level only
101 if ${PS} -p "$pid" >/dev/null 2>&1; then
102 kill $killlevel $pid 2>/dev/null
104 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
108 failure "$base shutdown"
110 # Remove pid file if any.
111 if [ "$notset" = "1" ]; then
112 rm -f ${PIDDIR}/$base.$2.pid
117 # A function to find the pid of a program.
122 echo "Usage: pidofproc {program}"
126 # Get base program name
130 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
131 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
132 if [ "$pid" != "" ] ; then
139 if [ -x ${PIDOF} ] ; then
142 if [ "$pid" != "" ] ; then
147 # Finally try to extract it from ps
148 pid=`${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' '`
157 echo "Usage: status {program} {port}"
161 # Get base program name
165 if [ -x ${PIDOF} ] ; then
168 if [ "$pid" != "" ] ; then
169 echo "$base (pid $pid) is running..."
172 pid=`${PSCMD} | ${AWK} 'BEGIN { prog=ARGV[1]; ARGC=1 }
173 { if ((prog == $2) || (("(" prog ")") == $2) ||
174 (("[" prog "]") == $2) ||
175 ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
176 if [ "$pid" != "" ] ; then
177 echo "$base (pid $pid) is running..."
182 # Next try the PID files
183 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
184 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
185 if [ "$pid" != "" ] ; then
186 echo "$base dead but pid file exists"
190 # See if the subsys lock exists
191 if [ -f ${SUBSYSDIR}/$base ] ; then
192 echo "$base dead but subsys locked"
195 echo "$base is stopped"
210 # if /lib/tls exists, force Bacula to use the glibc pthreads instead
211 if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then
212 export LD_ASSUME_KERNEL=2.4.19
217 [ -x ${BACFDBIN}/bacula-fd ] && {
218 echo "Starting the $Bacula File daemon"
220 if [ "${FD_USER}" != '' ]; then
221 OPTIONS="${OPTIONS} -u ${FD_USER}"
224 if [ "${FD_GROUP}" != '' ]; then
225 OPTIONS="${OPTIONS} -g ${FD_GROUP}"
228 if [ "x${VALGRIND_FD}" = "x1" ]; then
229 valgrind --leak-check=full ${BACFDBIN}/bacula-fd $2 $3 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf
231 ${BACFDBIN}/bacula-fd $2 $3 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf
237 # Stop the FD first so that SD will fail jobs and update catalog
238 [ -x ${BACFDBIN}/bacula-fd ] && {
239 echo "Stopping the $Bacula File daemon"
240 killproc ${BACFDBIN}/bacula-fd ${FD_PORT} $2
251 [ -x ${BACFDBIN}/bacula-fd ] && status ${BACFDBIN}/bacula-fd ${FD_PORT}
255 echo "Usage: $0 {start|stop|restart|status}"