3 # bacula-ctl-fd This shell script takes care of starting and stopping
4 # the bacula File daemon.
6 # This is pretty much watered down version of the RedHat script
7 # that works on Solaris as well as Linux, but it won't work everywhere.
9 # description: It comes by night and sucks the vital essence from your computers.
16 # On Solaris, you may need to use nawk, or alternatively,
17 # add the GNU binaries to your path, such as /usr/xpg4/bin
21 # All these are not *really* needed but it makes it
22 # easier to "steal" this code for the development
23 # environment where they are different.
37 # A function to stop a program.
42 echo "Usage: killproc {program} {port} [signal]"
47 # check for third arg to be kill level
48 if [ "$3" != "" ] ; then
55 # Get base program name
59 pid=`pidofproc $base $2`
62 if [ "$pid" != "" ] ; then
63 if [ "$notset" = "1" ] ; then
64 if ${PS} -p "$pid">/dev/null 2>&1; then
65 # TERM first, then KILL if not dead
66 kill -TERM $pid 2>/dev/null
68 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
70 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
72 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
73 kill -KILL $pid 2>/dev/null
78 ${PS} -p "$pid" >/dev/null 2>&1
80 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
82 # use specified level only
84 if ${PS} -p "$pid" >/dev/null 2>&1; then
85 kill $killlevel $pid 2>/dev/null
87 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
91 failure "$base shutdown"
93 # Remove pid file if any.
94 if [ "$notset" = "1" ]; then
95 rm -f ${PIDDIR}/$base.$2.pid
100 # A function to find the pid of a program.
105 echo "Usage: pidofproc {program}"
109 # Get base program name
113 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
114 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
115 if [ "$pid" != "" ] ; then
122 if [ -x ${PIDOF} ] ; then
125 if [ "$pid" != "" ] ; then
130 # Finally try to extract it from ps
131 pid=`${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' '`
140 echo "Usage: status {program} {port}"
144 # Get base program name
148 if [ -x ${PIDOF} ] ; then
151 if [ "$pid" != "" ] ; then
152 echo "$base (pid $pid) is running..."
155 pid=`${PSCMD} | ${AWK} 'BEGIN { prog=ARGV[1]; ARGC=1 }
156 { if ((prog == $2) || (("(" prog ")") == $2) ||
157 (("[" prog "]") == $2) ||
158 ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
159 if [ "$pid" != "" ] ; then
160 echo "$base (pid $pid) is running..."
165 # Next try the PID files
166 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
167 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
168 if [ "$pid" != "" ] ; then
169 echo "$base dead but pid file exists"
173 # See if the subsys lock exists
174 if [ -f ${SUBSYSDIR}/$base ] ; then
175 echo "$base dead but subsys locked"
178 echo "$base is stopped"
193 # if /lib/tls exists, force Bacula to use the glibc pthreads instead
194 if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then
195 export LD_ASSUME_KERNEL=2.4.19
200 [ -x ${BACFDBIN}/bacula-fd ] && {
201 echo "Starting the $Bacula File daemon"
203 if [ "${FD_USER}" != '' ]; then
204 OPTIONS="${OPTIONS} -u ${FD_USER}"
207 if [ "${FD_GROUP}" != '' ]; then
208 OPTIONS="${OPTIONS} -g ${FD_GROUP}"
211 ${BACFDBIN}/bacula-fd $2 $3 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf
216 # Stop the FD first so that SD will fail jobs and update catalog
217 [ -x ${BACFDBIN}/bacula-fd ] && {
218 echo "Stopping the $Bacula File daemon"
219 killproc ${BACFDBIN}/bacula-fd ${FD_PORT}
230 [ -x ${BACFDBIN}/bacula-fd ] && status ${BACFDBIN}/bacula-fd ${FD_PORT}
234 echo "Usage: $0 {start|stop|restart|status}"