3 # bacula-ctl-dir This shell script takes care of starting and stopping
4 # the bacula Director daemon
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.
16 # On Solaris, you may need to use nawk, or alternatively,
17 # add the GNU binaries to your path, such as /usr/xpg4/bin
21 # All these are not *really* needed but it makes it
22 # easier to "steal" this code for the development
23 # environment where they are different.
26 BACDIRCFG=@sysconfdir@
37 # A function to stop a program.
42 echo "Usage: killproc {program} {port} [signal]"
47 # check for third arg to be kill level
48 if [ "$3" != "" ] ; then
55 # Get base program name
59 pid=`pidofproc $base $2`
62 if [ "$pid" != "" ] ; then
63 if [ "$notset" = "1" ] ; then
64 if ${PS} -p "$pid">/dev/null 2>&1; then
65 # TERM first, then KILL if not dead
66 kill -TERM $pid 2>/dev/null
68 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
70 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
72 if ${PS} -p "$pid" >/dev/null 2>&1 ; then
73 kill -KILL $pid 2>/dev/null
78 ${PS} -p "$pid" >/dev/null 2>&1
80 [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown"
82 # use specified level only
84 if ${PS} -p "$pid" >/dev/null 2>&1; then
85 kill $killlevel $pid 2>/dev/null
87 [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel"
91 failure "$base shutdown"
93 # Remove pid file if any.
94 if [ "$notset" = "1" ]; then
95 rm -f ${PIDDIR}/$base.$2.pid
100 # A function to find the pid of a program.
105 echo "Usage: pidofproc {program}"
109 # Get base program name
113 if [ -f ${PIDDIR}/$base.$2.pid ] ; then
114 pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
115 if [ "$pid" != "" ] ; then
122 if [ -x ${PIDOF} ] ; then
125 if [ "$pid" != "" ] ; then
130 # Finally try to extract it from ps
131 ${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' '
139 echo "Usage: status {program} {port}"
143 # Get base program name
147 if [ -x ${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 -n 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 # if /lib/tls exists, force Bacula to use the glibc pthreads instead
193 if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then
194 export LD_ASSUME_KERNEL=2.4.19
199 [ -x ${BACDIRBIN}/bacula-dir ] && {
201 echo "Starting the Bacula Director daemon"
203 if [ "${DIR_USER}" != '' ]; then
204 OPTIONS="${OPTIONS} -u ${DIR_USER}"
207 if [ "${DIR_GROUP}" != '' ]; then
208 OPTIONS="${OPTIONS} -g ${DIR_GROUP}"
211 ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf
216 [ -x ${BACDIRBIN}/bacula-dir ] && {
217 echo "Stopping the Bacula Director daemon"
218 killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT}
229 [ -x ${BACDIRBIN}/bacula-dir ] && status ${BACDIRBIN}/bacula-dir ${DIR_PORT}
233 echo "Usage: $0 {start|stop|restart|status}"