]> git.sur5r.net Git - bacula/bacula/blob - bacula/scripts/devel_bacula.in
Adding double-quotes around $ready variable so that spaces do not impact pattern...
[bacula/bacula] / bacula / scripts / devel_bacula.in
1 #! /bin/sh
2 #
3 # bacula       This shell script takes care of starting and stopping
4 #              the bacula daemons.
5 #
6 #   It runs with different ports than the production version,
7 #   and using the current development enviornment.
8 #
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.
11 #
12 # description: It comes by night and sucks the vital essence from your computers.
13 #
14
15 PSCMD="@PSCMD@"
16 pwd=`pwd`
17
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
24 PIDDIR=@piddir@
25 SUBSYSDIR=@subsysdir@
26
27 # Use non-production ports
28 DIR_PORT=8101
29 FD_PORT=8102
30 SD_PORT=8103
31
32 DIR_USER=@dir_user@
33 DIR_GROUP=@dir_group@
34 FD_USER=@fd_user@
35 FD_GROUP=@fd_group@
36 SD_USER=@sd_user@
37 SD_GROUP=@sd_group@
38
39 # A function to stop a program.
40 killproc() {
41     RC=0
42     # Test syntax.
43     if [ $# = 0 ]; then
44         echo "Usage: killproc {program} [signal]"
45         return 1
46     fi
47
48     notset=0
49     # check for third arg to be kill level
50     if [ "$3" != "" ] ; then
51         killlevel=$3
52     else
53         notset=1
54         killlevel="-9"
55     fi
56
57     # Get base program name
58     base=`basename $1`
59
60     # Find pid.
61     pid=`pidofproc $base $2`
62
63     # Kill it.
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
69                 sleep 1
70                 if ps -p $pid >/dev/null 2>&1 ; then
71                     sleep 1
72                     if ps -p $pid >/dev/null 2>&1 ; then
73                         sleep 3
74                         if ps -p $pid >/dev/null 2>&1 ; then
75                             kill -KILL $pid 2>/dev/null
76                         fi
77                     fi
78                 fi
79              fi
80              ps -p $pid >/dev/null 2>&1
81              RC=$?
82              [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
83         #    RC=$((! $RC))
84         # use specified level only
85         else
86             if ps -p $pid >/dev/null 2>&1; then
87                 kill $killlevel $pid 2>/dev/null
88                 RC=$?
89                 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
90             fi
91         fi
92     else
93         failure "$base shutdown"
94     fi
95     # Remove pid file if any.
96     if [ "$notset" = "1" ]; then
97         rm -f ${PIDDIR}/$base.$2.pid
98     fi
99     return $RC
100 }
101
102 # A function to find the pid of a program.
103 pidofproc() {
104     pid=""
105     # Test syntax.
106     if [ $# = 0 ] ; then
107         echo "Usage: pidofproc {program}"
108         return 1
109     fi
110
111     # Get base program name
112     base=`basename $1`
113
114     # First try PID file
115     if [ -f ${PIDDIR}/$base.$2.pid ] ; then
116         pid=`head -1 ${PIDDIR}/$base.$2.pid`
117         if [ "$pid" != "" ] ; then
118             echo $pid
119             return 0
120         fi
121     fi
122
123     # Next try "pidof"
124    if [ -x /sbin/pidof ] ; then
125        pid=`/sbin/pidof $1`
126    fi
127    if [ "$pid" != "" ] ; then
128        echo $pid
129        return 0
130    fi
131
132     # Finally try to extract it from ps
133     ${PSCMD} | grep $1 | awk '{ print $1 }' | tr '\n' ' '
134     return 0
135 }
136
137 status() {
138     # Test syntax.
139     if [ $# = 0 ] ; then
140         echo "Usage: status {program}"
141         return 1
142     fi
143
144     # Get base program name
145     base=`basename $1`
146
147    # First try "pidof"
148    if [ -x /sbin/pidof ] ; then
149        pid=`/sbin/pidof $1`
150    fi
151    if [ "$pid" != "" ] ; then
152        echo "$base (pid $pid) is running..."
153        return 0
154    else
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..."
161            return 0
162        fi
163    fi
164
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"
170             return 1
171         fi
172     fi
173     # See if the subsys lock exists
174     if [ -f ${SUBSYSDIR}/$base ] ; then
175         echo "$base dead but subsys locked"
176         return 2
177     fi
178     echo "$base is stopped"
179     return 3
180 }
181
182 success() {
183   return 0
184 }
185
186 failure() {
187   rc=$?
188   return $rc
189 }
190
191 case "$1" in
192     start)
193        [ -x ${BACSDBIN}/bacula-sd ] && {
194           echo "Starting the Storage daemon"
195           OPTIONS=''
196           if [ "${SD_USER}" != '' ]; then
197              OPTIONS="${OPTIONS} -u ${SD_USER}"
198           fi
199
200           if [ "${SD_GROUP}" != '' ]; then
201              OPTIONS="${OPTIONS} -g ${SD_GROUP}"
202           fi
203
204           ${BACSDBIN}/bacula-sd $2 ${OPTIONS} -v -c ${BACSDCFG}/stored.conf
205        }
206
207        [ -x ${BACFDBIN}/bacula-fd ] && {
208           echo "Starting the File daemon"
209           OPTIONS=''
210           if [ "${FD_USER}" != '' ]; then
211              OPTIONS="${OPTIONS} -u ${FD_USER}"
212           fi
213
214           if [ "${FD_GROUP}" != '' ]; then
215              OPTIONS="${OPTIONS} -g ${FD_GROUP}"
216           fi
217
218           ${BACFDBIN}/bacula-fd $2 ${OPTIONS} -v -c ${BACFDCFG}/filed.conf
219        }
220
221        [ -x ${BACDIRBIN}/bacula-dir ] && { 
222            sleep 2
223            echo "Starting the Director daemon"
224           OPTIONS=''
225           if [ "${DIR_USER}" != '' ]; then
226              OPTIONS="${OPTIONS} -u ${DIR_USER}"
227           fi
228
229           if [ "${DIR_GROUP}" != '' ]; then
230              OPTIONS="${OPTIONS} -g ${DIR_GROUP}"
231           fi
232
233           if [ "${VALGRIND}" != '' ]; then
234              valgrind --leak-check=full ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/dird.conf
235           else
236              ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/dird.conf
237           fi
238        }
239        ;;
240
241     stop)
242        # Stop the FD first so that SD will fail jobs and update catalog
243        [ -x ${BACFDBIN}/bacula-fd ] && {
244           echo "Stopping the File daemon"
245           killproc ${BACFDBIN}/bacula-fd ${FD_PORT}
246        }
247
248        [ -x ${BACSDBIN}/bacula-sd ] && {
249           echo "Stopping the Storage daemon"
250           killproc ${BACSDBIN}/bacula-sd ${SD_PORT}
251        }
252
253        [ -x ${BACDIRBIN}/bacula-dir ] && {
254           echo "Stopping the Director daemon"
255           killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT}
256        }
257        echo
258        ;;
259
260     restart)
261        $0 stop
262        sleep 5
263        $0 start
264        ;;
265
266     status)
267        [ -x ${BACSDBIN}/bacula-sd   ] && status ${BACSDBIN}/bacula-sd  ${SD_PORT}
268        [ -x ${BACFDBIN}/bacula-fd   ] && status ${BACFDBIN}/bacula-fd  ${FD_PORT}
269        [ -x ${BACDIRBIN}/bacula-dir ] && status ${BACDIRBIN}/bacula-dir ${DIR_PORT}
270        ;;
271
272     *)
273        echo "Usage: $0 {start|stop|restart|status}"
274        exit 1
275        ;;
276 esac
277 exit 0