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.
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.
30 BACDIRCFG=@sysconfdir@
47 # A function to stop a program.
52 echo "Usage: killproc {program} {port} [signal]"
57 # check for third arg to be kill level
58 if [ "$3" != "" ] ; then
65 # Get base program name
69 pid=`pidofproc $base $2`
72 if [ "$pid" != "" ] ; then
73 if [ "$notset" = "1" ] ; then
74 if ${PS} -p $pid>/dev/null 2>&1; then
75 # TERM first, then KILL if not dead
76 kill -TERM $pid 2>/dev/null
78 if ${PS} -p $pid >/dev/null 2>&1 ; then
80 if ${PS} -p $pid >/dev/null 2>&1 ; then
82 if ${PS} -p $pid >/dev/null 2>&1 ; then
83 kill -KILL $pid 2>/dev/null
88 ${PS} -p $pid >/dev/null 2>&1
90 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
92 # use specified level only
94 if ${PS} -p $pid >/dev/null 2>&1; then
95 kill $killlevel $pid 2>/dev/null
97 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
101 failure "$base shutdown"
103 # Remove pid file if any.
104 if [ "$notset" = "1" ]; then
105 rm -f ${PIDDIR}/$base.$2.pid
110 # A function to find the pid of a program.
115 echo "Usage: pidofproc {program}"
119 # Get base program name
123 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
124 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
125 if [ "$pid" != "" ] ; then
132 if [ -x ${PIDOF} ] ; then
135 if [ "$pid" != "" ] ; then
140 # Finally try to extract it from ps
141 ${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' '
149 echo "Usage: status {program} {port}"
153 # Get base program name
157 if [ -x ${PIDOF} ] ; then
160 if [ "$pid" != "" ] ; then
161 echo "$base (pid $pid) is running..."
164 pid=`${PSCMD} | ${AWK} 'BEGIN { prog=ARGV[1]; ARGC=1 }
165 { if ((prog == $2) || (("(" prog ")") == $2) ||
166 (("[" prog "]") == $2) ||
167 ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
168 if [ "$pid" != "" ] ; then
169 echo "$base (pid $pid) is running..."
174 # Next try the PID files
175 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
176 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
177 if [ "$pid" != "" ] ; then
178 echo "$base dead but pid file exists"
182 # See if the subsys lock exists
183 if [ -f ${SUBSYSDIR}/$base ] ; then
184 echo "$base dead but subsys locked"
187 echo "$base is stopped"
202 # if /lib/tls exists, force Bacula to use the glibc pthreads instead
203 if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then
204 export LD_ASSUME_KERNEL=2.4.19
209 [ -x ${BACSDBIN}/bacula-sd ] && {
210 echo "Starting the Bacula Storage daemon"
212 if [ "${SD_USER}" != '' ]; then
213 OPTIONS="${OPTIONS} -u ${SD_USER}"
216 if [ "${SD_GROUP}" != '' ]; then
217 OPTIONS="${OPTIONS} -g ${SD_GROUP}"
220 ${BACSDBIN}/bacula-sd $2 ${OPTIONS} -v -c ${BACSDCFG}/bacula-sd.conf
223 [ -x ${BACFDBIN}/bacula-fd ] && {
224 echo "Starting the Bacula File daemon"
226 if [ "${FD_USER}" != '' ]; then
227 OPTIONS="${OPTIONS} -u ${FD_USER}"
230 if [ "${FD_GROUP}" != '' ]; then
231 OPTIONS="${OPTIONS} -g ${FD_GROUP}"
234 ${BACFDBIN}/bacula-fd $2 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf
237 [ -x ${BACDIRBIN}/bacula-dir ] && {
239 echo "Starting the Bacula Director daemon"
241 if [ "${DIR_USER}" != '' ]; then
242 OPTIONS="${OPTIONS} -u ${DIR_USER}"
245 if [ "${DIR_GROUP}" != '' ]; then
246 OPTIONS="${OPTIONS} -g ${DIR_GROUP}"
249 ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf
254 # Stop the FD first so that SD will fail jobs and update catalog
255 [ -x ${BACFDBIN}/bacula-fd ] && {
256 echo "Stopping the Bacula File daemon"
257 killproc ${BACFDBIN}/bacula-fd ${FD_PORT}
260 [ -x ${BACSDBIN}/bacula-sd ] && {
261 echo "Stopping the Bacula Storage daemon"
262 killproc ${BACSDBIN}/bacula-sd ${SD_PORT}
265 [ -x ${BACDIRBIN}/bacula-dir ] && {
266 echo "Stopping the Bacula Director daemon"
267 killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT}
279 [ -x ${BACSDBIN}/bacula-sd ] && status ${BACSDBIN}/bacula-sd ${SD_PORT}
280 [ -x ${BACFDBIN}/bacula-fd ] && status ${BACFDBIN}/bacula-fd ${FD_PORT}
281 [ -x ${BACDIRBIN}/bacula-dir ] && status ${BACDIRBIN}/bacula-dir ${DIR_PORT}
285 echo "Usage: $0 {start|stop|restart|status}"