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.
30 # A function to stop a program.
35 echo "Usage: killproc {program} [signal]"
40 # check for third arg to be kill level
41 if [ "$3" != "" ] ; then
48 # Get base program name
52 pid=`pidofproc $base $2`
55 if [ "$pid" != "" ] ; then
56 if [ "$notset" = "1" ] ; then
57 if ps -p $pid>/dev/null 2>&1; then
58 # TERM first, then KILL if not dead
59 kill -TERM $pid 2>/dev/null
61 if ps -p $pid >/dev/null 2>&1 ; then
63 if ps -p $pid >/dev/null 2>&1 ; then
65 if ps -p $pid >/dev/null 2>&1 ; then
66 kill -KILL $pid 2>/dev/null
71 ps -p $pid >/dev/null 2>&1
73 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
75 # use specified level only
77 if ps -p $pid >/dev/null 2>&1; then
78 kill $killlevel $pid 2>/dev/null
80 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
84 failure "$base shutdown"
86 # Remove pid file if any.
87 if [ "$notset" = "1" ]; then
88 rm -f ${PIDDIR}/$base.$2.pid
93 # A function to find the pid of a program.
98 echo "Usage: pidofproc {program}"
102 # Get base program name
106 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
107 pid=`head -1 ${PIDDIR}/$base.$2.pid`
108 if [ "$pid" != "" ] ; then
115 if [ -x /sbin/pidof ] ; then
118 if [ "$pid" != "" ] ; then
123 # Finally try to extract it from ps
124 ${PSCMD} | grep $1 | awk '{ print $1 }' | tr '\n' ' '
131 echo "Usage: status {program}"
135 # Get base program name
139 if [ -x /sbin/pidof ] ; then
142 if [ "$pid" != "" ] ; then
143 echo "$base (pid $pid) is running..."
146 pid=`${PSCMD} | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
147 { if ((prog == $2) || (("(" prog ")") == $2) ||
148 (("[" prog "]") == $2) ||
149 ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
150 if [ "$pid" != "" ] ; then
151 echo "$base (pid $pid) is running..."
156 # Next try the PID files
157 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
158 pid=`head -1 ${PIDDIR}/$base.$2.pid`
159 if [ "$pid" != "" ] ; then
160 echo "$base dead but pid file exists"
164 # See if the subsys lock exists
165 if [ -f ${SUBSYSDIR}/$base ] ; then
166 echo "$base dead but subsys locked"
169 echo "$base is stopped"
184 [ -x ${BACBIN}/bacula-sd ] && {
185 echo "Starting the Storage daemon"
187 if [ "${SD_USER}" != '' ]; then
188 OPTIONS="${OPTIONS} -u ${SD_USER}"
191 if [ "${SD_GROUP}" != '' ]; then
192 OPTIONS="${OPTIONS} -g ${SD_GROUP}"
195 ${BACBIN}/bacula-sd $2 ${OPTIONS} -v -c ${BACCFG}/bacula-sd.conf
198 [ -x ${BACBIN}/bacula-fd ] && {
199 echo "Starting the File daemon"
201 if [ "${FD_USER}" != '' ]; then
202 OPTIONS="${OPTIONS} -u ${FD_USER}"
205 if [ "${FD_GROUP}" != '' ]; then
206 OPTIONS="${OPTIONS} -g ${FD_GROUP}"
209 ${BACBIN}/bacula-fd $2 ${OPTIONS} -v -c ${BACCFG}/bacula-fd.conf
212 [ -x ${BACBIN}/bacula-dir ] && {
214 echo "Starting the Director daemon"
216 if [ "${DIR_USER}" != '' ]; then
217 OPTIONS="${OPTIONS} -u ${DIR_USER}"
220 if [ "${DIR_GROUP}" != '' ]; then
221 OPTIONS="${OPTIONS} -g ${DIR_GROUP}"
224 ${BACBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACCFG}/bacula-dir.conf
229 # Stop the FD first so that SD will fail jobs and update catalog
230 [ -x ${BACBIN}/bacula-fd ] && {
231 echo "Stopping the File daemon"
232 killproc ${BACBIN}/bacula-fd ${FD_PORT}
235 [ -x ${BACBIN}/bacula-sd ] && {
236 echo "Stopping the Storage daemon"
237 killproc ${BACBIN}/bacula-sd ${SD_PORT}
240 [ -x ${BACBIN}/bacula-dir ] && {
241 echo "Stopping the Director daemon"
242 killproc ${BACBIN}/bacula-dir ${DIR_PORT}
254 [ -x ${BACBIN}/bacula-sd ] && status ${BACBIN}/bacula-sd ${SD_PORT}
255 [ -x ${BACBIN}/bacula-fd ] && status ${BACBIN}/bacula-fd ${FD_PORT}
256 [ -x ${BACBIN}/bacula-dir ] && status ${BACBIN}/bacula-dir ${DIR_PORT}
260 echo "Usage: $0 {start|stop|restart|status}"