3 # Copyright (C) 2000-2016 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
6 # bacula This shell script takes care of starting and stopping
9 # It runs with different ports than the production version,
10 # and using the current development enviornment.
12 # This is pretty much watered down version of the RedHat script
13 # that works on Solaris as well as Linux, but it won't work everywhere.
15 # description: The Leading Open Source Backup Solution.
21 BACDIRBIN=${pwd}/src/dird
22 BACDIRCFG=${pwd}/src/dird
23 BACFDBIN=${pwd}/src/filed
24 BACFDCFG=${pwd}/src/filed
25 BACSDBIN=${pwd}/src/stored
26 BACSDCFG=${pwd}/src/stored
30 # Use non-production ports
42 # A function to stop a program.
47 echo "Usage: killproc {program} [signal]"
52 # check for third arg to be kill level
53 if [ "$3" != "" ] ; then
60 # Get base program name
64 pid=`pidofproc $base $2`
67 if [ "$pid" != "" ] ; then
68 if [ "$notset" = "1" ] ; then
69 if ps -p $pid>/dev/null 2>&1; then
70 # TERM first, then KILL if not dead
71 kill -TERM $pid 2>/dev/null
73 if ps -p $pid >/dev/null 2>&1 ; then
75 if ps -p $pid >/dev/null 2>&1 ; then
77 if ps -p $pid >/dev/null 2>&1 ; then
78 kill -KILL $pid 2>/dev/null
83 ps -p $pid >/dev/null 2>&1
85 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
87 # use specified level only
89 if ps -p $pid >/dev/null 2>&1; then
90 kill $killlevel $pid 2>/dev/null
92 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
96 failure "$base shutdown"
98 # Remove pid file if any.
99 if [ "$notset" = "1" ]; then
100 rm -f ${PIDDIR}/$base.$2.pid
105 # A function to find the pid of a program.
110 echo "Usage: pidofproc {program}"
114 # Get base program name
118 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
119 pid=`head -1 ${PIDDIR}/$base.$2.pid`
120 if [ "$pid" != "" ] ; then
127 if [ -x /sbin/pidof ] ; then
130 if [ "$pid" != "" ] ; then
135 # Finally try to extract it from ps
136 ${PSCMD} | grep $1 | awk '{ print $1 }' | tr '\n' ' '
143 echo "Usage: status {program}"
147 # Get base program name
151 if [ -x /sbin/pidof ] ; then
154 if [ "$pid" != "" ] ; then
155 echo "$base (pid $pid) is running..."
158 pid=`${PSCMD} | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
159 { if ((prog == $2) || (("(" prog ")") == $2) ||
160 (("[" prog "]") == $2) ||
161 ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
162 if [ "$pid" != "" ] ; then
163 echo "$base (pid $pid) is running..."
168 # Next try the PID files
169 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
170 pid=`head -1 ${PIDDIR}/$base.$2.pid`
171 if [ "$pid" != "" ] ; then
172 echo "$base dead but pid file exists"
176 # See if the subsys lock exists
177 if [ -f ${SUBSYSDIR}/$base ] ; then
178 echo "$base dead but subsys locked"
181 echo "$base is stopped"
196 [ -x ${BACSDBIN}/bacula-sd ] && {
197 echo "Starting the Storage daemon"
199 if [ "${SD_USER}" != '' ]; then
200 OPTIONS="${OPTIONS} -u ${SD_USER}"
203 if [ "${SD_GROUP}" != '' ]; then
204 OPTIONS="${OPTIONS} -g ${SD_GROUP}"
207 ${BACSDBIN}/bacula-sd $2 ${OPTIONS} -v -c ${BACSDCFG}/stored.conf
210 [ -x ${BACFDBIN}/bacula-fd ] && {
211 echo "Starting the File daemon"
213 if [ "${FD_USER}" != '' ]; then
214 OPTIONS="${OPTIONS} -u ${FD_USER}"
217 if [ "${FD_GROUP}" != '' ]; then
218 OPTIONS="${OPTIONS} -g ${FD_GROUP}"
221 ${BACFDBIN}/bacula-fd $2 ${OPTIONS} -v -c ${BACFDCFG}/filed.conf
224 [ -x ${BACDIRBIN}/bacula-dir ] && {
226 echo "Starting the Director daemon"
228 if [ "${DIR_USER}" != '' ]; then
229 OPTIONS="${OPTIONS} -u ${DIR_USER}"
232 if [ "${DIR_GROUP}" != '' ]; then
233 OPTIONS="${OPTIONS} -g ${DIR_GROUP}"
236 if [ "${VALGRIND}" != '' ]; then
237 valgrind --leak-check=full ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/dird.conf
239 ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/dird.conf
245 # Stop the FD first so that SD will fail jobs and update catalog
246 [ -x ${BACFDBIN}/bacula-fd ] && {
247 echo "Stopping the File daemon"
248 killproc ${BACFDBIN}/bacula-fd ${FD_PORT}
251 [ -x ${BACSDBIN}/bacula-sd ] && {
252 echo "Stopping the Storage daemon"
253 killproc ${BACSDBIN}/bacula-sd ${SD_PORT}
256 [ -x ${BACDIRBIN}/bacula-dir ] && {
257 echo "Stopping the Director daemon"
258 killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT}
270 [ -x ${BACSDBIN}/bacula-sd ] && status ${BACSDBIN}/bacula-sd ${SD_PORT}
271 [ -x ${BACFDBIN}/bacula-fd ] && status ${BACFDBIN}/bacula-fd ${FD_PORT}
272 [ -x ${BACDIRBIN}/bacula-dir ] && status ${BACDIRBIN}/bacula-dir ${DIR_PORT}
276 echo "Usage: $0 {start|stop|restart|status}"