3 # bacula This shell script takes care of starting and stopping
6 # It runs with different ports than the production version,
7 # and using the current development enviornment.
9 # This is pretty much watered down version of the RedHat script
10 # that works on Solaris as well as Linux, but it won't work everywhere.
12 # description: It comes by night and sucks the vital essence from your computers.
18 BACDIRBIN=${pwd}/src/dird
19 BACDIRCFG=${pwd}/src/dird
20 BACFDBIN=${pwd}/src/filed
21 BACFDCFG=${pwd}/src/filed
22 BACSDBIN=${pwd}/src/stored
23 BACSDCFG=${pwd}/src/stored
27 # Use non-production ports
39 # A function to stop a program.
44 echo "Usage: killproc {program} [signal]"
49 # check for third arg to be kill level
50 if [ "$3" != "" ] ; then
57 # Get base program name
61 pid=`pidofproc $base $2`
64 if [ "$pid" != "" ] ; then
65 if [ "$notset" = "1" ] ; then
66 if ps -p $pid>/dev/null 2>&1; then
67 # TERM first, then KILL if not dead
68 kill -TERM $pid 2>/dev/null
70 if ps -p $pid >/dev/null 2>&1 ; then
72 if ps -p $pid >/dev/null 2>&1 ; then
74 if ps -p $pid >/dev/null 2>&1 ; then
75 kill -KILL $pid 2>/dev/null
80 ps -p $pid >/dev/null 2>&1
82 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
84 # use specified level only
86 if ps -p $pid >/dev/null 2>&1; then
87 kill $killlevel $pid 2>/dev/null
89 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
93 failure "$base shutdown"
95 # Remove pid file if any.
96 if [ "$notset" = "1" ]; then
97 rm -f ${PIDDIR}/$base.$2.pid
102 # A function to find the pid of a program.
107 echo "Usage: pidofproc {program}"
111 # Get base program name
115 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
116 pid=`head -1 ${PIDDIR}/$base.$2.pid`
117 if [ "$pid" != "" ] ; then
124 if [ -x /sbin/pidof ] ; then
127 if [ "$pid" != "" ] ; then
132 # Finally try to extract it from ps
133 ${PSCMD} | grep $1 | awk '{ print $1 }' | tr '\n' ' '
140 echo "Usage: status {program}"
144 # Get base program name
148 if [ -x /sbin/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 -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 [ -x ${BACSDBIN}/bacula-sd ] && {
194 echo "Starting the Storage daemon"
196 if [ "${SD_USER}" != '' ]; then
197 OPTIONS="${OPTIONS} -u ${SD_USER}"
200 if [ "${SD_GROUP}" != '' ]; then
201 OPTIONS="${OPTIONS} -g ${SD_GROUP}"
204 ${BACSDBIN}/bacula-sd $2 ${OPTIONS} -v -c ${BACSDCFG}/stored.conf
207 [ -x ${BACFDBIN}/bacula-fd ] && {
208 echo "Starting the File daemon"
210 if [ "${FD_USER}" != '' ]; then
211 OPTIONS="${OPTIONS} -u ${FD_USER}"
214 if [ "${FD_GROUP}" != '' ]; then
215 OPTIONS="${OPTIONS} -g ${FD_GROUP}"
218 ${BACFDBIN}/bacula-fd $2 ${OPTIONS} -v -c ${BACFDCFG}/filed.conf
221 [ -x ${BACDIRBIN}/bacula-dir ] && {
223 echo "Starting the Director daemon"
225 if [ "${DIR_USER}" != '' ]; then
226 OPTIONS="${OPTIONS} -u ${DIR_USER}"
229 if [ "${DIR_GROUP}" != '' ]; then
230 OPTIONS="${OPTIONS} -g ${DIR_GROUP}"
233 # valgrind --leak-check=full ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/dird.conf
234 ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/dird.conf
239 # Stop the FD first so that SD will fail jobs and update catalog
240 [ -x ${BACFDBIN}/bacula-fd ] && {
241 echo "Stopping the File daemon"
242 killproc ${BACFDBIN}/bacula-fd ${FD_PORT}
245 [ -x ${BACSDBIN}/bacula-sd ] && {
246 echo "Stopping the Storage daemon"
247 killproc ${BACSDBIN}/bacula-sd ${SD_PORT}
250 [ -x ${BACDIRBIN}/bacula-dir ] && {
251 echo "Stopping the Director daemon"
252 killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT}
264 [ -x ${BACSDBIN}/bacula-sd ] && status ${BACSDBIN}/bacula-sd ${SD_PORT}
265 [ -x ${BACFDBIN}/bacula-fd ] && status ${BACFDBIN}/bacula-fd ${FD_PORT}
266 [ -x ${BACDIRBIN}/bacula-dir ] && status ${BACDIRBIN}/bacula-dir ${DIR_PORT}
270 echo "Usage: $0 {start|stop|restart|status}"