3 # bacula This shell script takes care of starting and stopping
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.
15 # On Solaris, you may need to use nawk, or alternatively,
16 # add the GNU binaries to your path, such as /usr/xpg4/bin
20 # All these are not *really* needed but it makes it
21 # easier to "steal" this code for the development
22 # environment where they are different.
29 BACDIRCFG=@sysconfdir@
46 # A function to stop a program.
51 echo "Usage: killproc {program} [signal]"
56 # check for third arg to be kill level
57 if [ "$3" != "" ] ; then
64 # Get base program name
68 pid=`pidofproc $base $2`
71 if [ "$pid" != "" ] ; then
72 if [ "$notset" = "1" ] ; then
73 if ps -p $pid>/dev/null 2>&1; then
74 # TERM first, then KILL if not dead
75 kill -TERM $pid 2>/dev/null
77 if ps -p $pid >/dev/null 2>&1 ; then
79 if ps -p $pid >/dev/null 2>&1 ; then
81 if ps -p $pid >/dev/null 2>&1 ; then
82 kill -KILL $pid 2>/dev/null
87 ps -p $pid >/dev/null 2>&1
89 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
91 # use specified level only
93 if ps -p $pid >/dev/null 2>&1; then
94 kill $killlevel $pid 2>/dev/null
96 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
100 failure "$base shutdown"
102 # Remove pid file if any.
103 if [ "$notset" = "1" ]; then
104 rm -f ${PIDDIR}/$base.$2.pid
109 # A function to find the pid of a program.
114 echo "Usage: pidofproc {program}"
118 # Get base program name
122 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
123 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
124 if [ "$pid" != "" ] ; then
131 if [ -x ${PIDOF} ] ; then
134 if [ "$pid" != "" ] ; then
139 # Finally try to extract it from ps
140 ${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' '
148 echo "Usage: status {program}"
152 # Get base program name
156 if [ -x ${PIDOF} ] ; then
159 if [ "$pid" != "" ] ; then
160 echo "$base (pid $pid) is running..."
163 pid=`${PSCMD} | ${AWK} 'BEGIN { prog=ARGV[1]; ARGC=1 }
164 { if ((prog == $2) || (("(" prog ")") == $2) ||
165 (("[" prog "]") == $2) ||
166 ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
167 if [ "$pid" != "" ] ; then
168 echo "$base (pid $pid) is running..."
173 # Next try the PID files
174 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
175 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
176 if [ "$pid" != "" ] ; then
177 echo "$base dead but pid file exists"
181 # See if the subsys lock exists
182 if [ -f ${SUBSYSDIR}/$base ] ; then
183 echo "$base dead but subsys locked"
186 echo "$base is stopped"
201 # if /lib/tls exists, force Bacula to use the glibc pthreads instead
202 if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then
203 export LD_ASSUME_KERNEL=2.4.19
208 [ -x ${BACSDBIN}/bacula-sd ] && {
209 echo "Starting the Bacula Storage daemon"
211 if [ "${SD_USER}" != '' ]; then
212 OPTIONS="${OPTIONS} -u ${SD_USER}"
215 if [ "${SD_GROUP}" != '' ]; then
216 OPTIONS="${OPTIONS} -g ${SD_GROUP}"
219 ${BACSDBIN}/bacula-sd $2 ${OPTIONS} -v -c ${BACSDCFG}/bacula-sd.conf
222 [ -x ${BACFDBIN}/bacula-fd ] && {
223 echo "Starting the Bacula File daemon"
225 if [ "${FD_USER}" != '' ]; then
226 OPTIONS="${OPTIONS} -u ${FD_USER}"
229 if [ "${FD_GROUP}" != '' ]; then
230 OPTIONS="${OPTIONS} -g ${FD_GROUP}"
233 ${BACFDBIN}/bacula-fd $2 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf
236 [ -x ${BACDIRBIN}/bacula-dir ] && {
238 echo "Starting the Bacula Director daemon"
240 if [ "${DIR_USER}" != '' ]; then
241 OPTIONS="${OPTIONS} -u ${DIR_USER}"
244 if [ "${DIR_GROUP}" != '' ]; then
245 OPTIONS="${OPTIONS} -g ${DIR_GROUP}"
248 ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf
253 # Stop the FD first so that SD will fail jobs and update catalog
254 [ -x ${BACFDBIN}/bacula-fd ] && {
255 echo "Stopping the Bacula File daemon"
256 killproc ${BACFDBIN}/bacula-fd ${FD_PORT}
259 [ -x ${BACSDBIN}/bacula-sd ] && {
260 echo "Stopping the Bacula Storage daemon"
261 killproc ${BACSDBIN}/bacula-sd ${SD_PORT}
264 [ -x ${BACDIRBIN}/bacula-dir ] && {
265 echo "Stopping the Bacula Director daemon"
266 killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT}
278 [ -x ${BACSDBIN}/bacula-sd ] && status ${BACSDBIN}/bacula-sd ${SD_PORT}
279 [ -x ${BACFDBIN}/bacula-fd ] && status ${BACFDBIN}/bacula-fd ${FD_PORT}
280 [ -x ${BACDIRBIN}/bacula-dir ] && status ${BACDIRBIN}/bacula-dir ${DIR_PORT}
284 echo "Usage: $0 {start|stop|restart|status}"