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.
14 # All these are not *really* needed but it makes it
15 # easier to "steal" this code for the development
16 # environment where they are different.
23 BACDIRCFG=@sysconfdir@
38 # A function to stop a program.
43 echo "Usage: killproc {program} [signal]"
48 # check for third arg to be kill level
49 if [ "$3" != "" ] ; then
56 # Get base program name
60 pid=`pidofproc $base $2`
63 if [ "$pid" != "" ] ; then
64 if [ "$notset" = "1" ] ; then
65 if ps -p $pid>/dev/null 2>&1; then
66 # TERM first, then KILL if not dead
67 kill -TERM $pid 2>/dev/null
69 if ps -p $pid >/dev/null 2>&1 ; then
71 if ps -p $pid >/dev/null 2>&1 ; then
73 if ps -p $pid >/dev/null 2>&1 ; then
74 kill -KILL $pid 2>/dev/null
79 ps -p $pid >/dev/null 2>&1
81 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
83 # use specified level only
85 if ps -p $pid >/dev/null 2>&1; then
86 kill $killlevel $pid 2>/dev/null
88 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
92 failure "$base shutdown"
94 # Remove pid file if any.
95 if [ "$notset" = "1" ]; then
96 rm -f ${PIDDIR}/$base.$2.pid
101 # A function to find the pid of a program.
106 echo "Usage: pidofproc {program}"
110 # Get base program name
114 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
115 pid=`head -1 ${PIDDIR}/$base.$2.pid`
116 if [ "$pid" != "" ] ; then
123 if [ -x /sbin/pidof ] ; then
126 if [ "$pid" != "" ] ; then
131 # Finally try to extract it from ps
132 ${PSCMD} | grep $1 | awk '{ print $1 }' | tr '\n' ' '
139 echo "Usage: status {program}"
143 # Get base program name
147 if [ -x /sbin/pidof ] ; then
150 if [ "$pid" != "" ] ; then
151 echo "$base (pid $pid) is running..."
154 pid=`${PSCMD} | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
155 { if ((prog == $2) || (("(" prog ")") == $2) ||
156 (("[" prog "]") == $2) ||
157 ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
158 if [ "$pid" != "" ] ; then
159 echo "$base (pid $pid) is running..."
164 # Next try the PID files
165 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
166 pid=`head -1 ${PIDDIR}/$base.$2.pid`
167 if [ "$pid" != "" ] ; then
168 echo "$base dead but pid file exists"
172 # See if the subsys lock exists
173 if [ -f ${SUBSYSDIR}/$base ] ; then
174 echo "$base dead but subsys locked"
177 echo "$base is stopped"
192 [ -x ${BACSDBIN}/bacula-sd ] && {
193 echo "Starting the Storage daemon"
195 if [ "${SD_USER}" != '' ]; then
196 OPTIONS="${OPTIONS} -u ${SD_USER}"
199 if [ "${SD_GROUP}" != '' ]; then
200 OPTIONS="${OPTIONS} -g ${SD_GROUP}"
203 ${BACSDBIN}/bacula-sd $2 ${OPTIONS} -v -c ${BACSDCFG}/bacula-sd.conf
206 [ -x ${BACFDBIN}/bacula-fd ] && {
207 echo "Starting the File daemon"
209 if [ "${FD_USER}" != '' ]; then
210 OPTIONS="${OPTIONS} -u ${FD_USER}"
213 if [ "${FD_GROUP}" != '' ]; then
214 OPTIONS="${OPTIONS} -g ${FD_GROUP}"
217 ${BACFDBIN}/bacula-fd $2 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf
220 [ -x ${BACDIRBIN}/bacula-dir ] && {
222 echo "Starting the Director daemon"
224 if [ "${DIR_USER}" != '' ]; then
225 OPTIONS="${OPTIONS} -u ${DIR_USER}"
228 if [ "${DIR_GROUP}" != '' ]; then
229 OPTIONS="${OPTIONS} -g ${DIR_GROUP}"
232 ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf
237 # Stop the FD first so that SD will fail jobs and update catalog
238 [ -x ${BACFDBIN}/bacula-fd ] && {
239 echo "Stopping the File daemon"
240 killproc ${BACFDBIN}/bacula-fd ${FD_PORT}
243 [ -x ${BACSDBIN}/bacula-sd ] && {
244 echo "Stopping the Storage daemon"
245 killproc ${BACSDBIN}/bacula-sd ${SD_PORT}
248 [ -x ${BACDIRBIN}/bacula-dir ] && {
249 echo "Stopping the Director daemon"
250 killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT}
262 [ -x ${BACSDBIN}/bacula-sd ] && status ${BACSDBIN}/bacula-sd ${SD_PORT}
263 [ -x ${BACFDBIN}/bacula-fd ] && status ${BACFDBIN}/bacula-fd ${FD_PORT}
264 [ -x ${BACDIRBIN}/bacula-dir ] && status ${BACDIRBIN}/bacula-dir ${DIR_PORT}
268 echo "Usage: $0 {start|stop|restart|status}"