]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/scripts/bacula.in
Fix scripts/bacula.in to have awk on an environment variable
[bacula/bacula] / bacula / scripts / bacula.in
index dbbed1203c9bdfd25e9405e151562c446a695ee8..b530ad8cf3b2af66b1c6937d922216b227ef7e40 100755 (executable)
 
 PSCMD="@PSCMD@"
 
+#
+# On Solaris, you may need to use nawk, or alternatively,
+#  add the GNU binaries to your path, such as /usr/xpg4/bin
+#
+AWK=awk
+
+# All these are not *really* needed but it makes it
+#  easier to "steal" this code for the development 
+#  environment where they are different.
+#  
+BACFDBIN=@sbindir@
+BACFDCFG=@sysconfdir@
+BACSDBIN=@sbindir@
+BACSDCFG=@sysconfdir@
+BACDIRBIN=@sbindir@
+BACDIRCFG=@sysconfdir@
+PIDDIR=@piddir@
+SUBSYSDIR=@subsysdir@
+
+DIR_PORT=@dir_port@
+FD_PORT=@fd_port@
+SD_PORT=@sd_port@
+
+DIR_USER=@dir_user@
+DIR_GROUP=@dir_group@
+FD_USER=@fd_user@
+FD_GROUP=@fd_group@
+SD_USER=@sd_user@
+SD_GROUP=@sd_group@
+
+PIDOF=@PIDOF@  
+
 # A function to stop a program.
 killproc() {
     RC=0
@@ -69,7 +101,7 @@ killproc() {
     fi
     # Remove pid file if any.
     if [ "$notset" = "1" ]; then
-       rm -f @piddir@/$base.$2.pid
+       rm -f ${PIDDIR}/$base.$2.pid
     fi
     return $RC
 }
@@ -87,8 +119,8 @@ pidofproc() {
     base=`basename $1`
 
     # First try PID file
-    if [ -f @piddir@/$base.$2.pid ] ; then
-       pid=`head -1 @piddir@/$base.$2.pid`
+    if [ -f ${PIDDIR}/$base.$2.pid ] ; then
+       pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
        if [ "$pid" != "" ] ; then
            echo $pid
            return 0
@@ -96,8 +128,8 @@ pidofproc() {
     fi
 
     # Next try "pidof"
-   if [ -x /sbin/pidof ] ; then
-       pid=`/sbin/pidof $1`
+   if [ -x ${PIDOF} ] ; then
+       pid=`${PIDOF} $1`
    fi
    if [ "$pid" != "" ] ; then
        echo $pid
@@ -105,11 +137,12 @@ pidofproc() {
    fi
 
     # Finally try to extract it from ps
-    ${PSCMD} | grep $1 | awk '{ print $1 }' | tr '\n' ' '
+    ${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' '
     return 0
 }
 
 status() {
+    pid=""
     # Test syntax.
     if [ $# = 0 ] ; then
        echo "Usage: status {program}"
@@ -120,14 +153,14 @@ status() {
     base=`basename $1`
 
    # First try "pidof"
-   if [ -x /sbin/pidof ] ; then
-       pid=`/sbin/pidof $1`
+   if [ -x ${PIDOF} ] ; then
+       pid=`${PIDOF} $1`
    fi
    if [ "$pid" != "" ] ; then
        echo "$base (pid $pid) is running..."
        return 0
    else
-       pid=`${PSCMD} | awk 'BEGIN { prog=ARGV[1]; ARGC=1 } 
+       pid=`${PSCMD} | ${AWK} 'BEGIN { prog=ARGV[1]; ARGC=1 } 
             { if ((prog == $2) || (("(" prog ")") == $2) ||
                  (("[" prog "]") == $2) ||
                  ((prog ":") == $2)) { print $1 ; exit 0 } }' $1`
@@ -138,15 +171,15 @@ status() {
    fi
 
     # Next try the PID files
-    if [ -f @piddir@/$base.$2.pid ] ; then
-       pid=`head -1 @piddir@/$base.$2.pid`
+    if [ -f ${PIDDIR}/$base.$2.pid ] ; then
+       pid=`head -n 1 ${PIDDIR}/$base.$2.pid`
        if [ "$pid" != "" ] ; then
            echo "$base dead but pid file exists"
            return 1
        fi
     fi
     # See if the subsys lock exists
-    if [ -f @subsysdir@/$base ] ; then
+    if [ -f ${SUBSYSDIR}/$base ] ; then
        echo "$base dead but subsys locked"
        return 2
     fi
@@ -163,35 +196,90 @@ failure() {
   return $rc
 }
 
+OS=`uname -s`
+
+# if /lib/tls exists, force Bacula to use the glibc pthreads instead
+if [ -d "/lib/tls" -a $OS = "Linux" ] ; then
+     export LD_ASSUME_KERNEL=2.4.19
+fi
+
 case "$1" in
     start)
-       echo "Starting the Storage daemon"
-       @sbindir@/bacula-sd $2 -c @sysconfdir@/bacula-sd.conf
-       echo "Starting the File daemon"
-       @sbindir@/bacula-fd $2 -c @sysconfdir@/bacula-fd.conf
-       sleep 2
-       echo "Starting the Director daemon"
-       @sbindir@/bacula-dir $2 -c @sysconfdir@/bacula-dir.conf
+       [ -x ${BACSDBIN}/bacula-sd ] && {
+         echo "Starting the Bacula Storage daemon"
+         OPTIONS=''
+         if [ "${SD_USER}" != '' ]; then
+            OPTIONS="${OPTIONS} -u ${SD_USER}"
+         fi
+
+         if [ "${SD_GROUP}" != '' ]; then
+            OPTIONS="${OPTIONS} -g ${SD_GROUP}"
+         fi
+
+         ${BACSDBIN}/bacula-sd $2 ${OPTIONS} -v -c ${BACSDCFG}/bacula-sd.conf
+       }
+
+       [ -x ${BACFDBIN}/bacula-fd ] && {
+         echo "Starting the Bacula File daemon"
+         OPTIONS=''
+         if [ "${FD_USER}" != '' ]; then
+            OPTIONS="${OPTIONS} -u ${FD_USER}"
+         fi
+
+         if [ "${FD_GROUP}" != '' ]; then
+            OPTIONS="${OPTIONS} -g ${FD_GROUP}"
+         fi
+
+         ${BACFDBIN}/bacula-fd $2 ${OPTIONS} -v -c ${BACFDCFG}/bacula-fd.conf
+       }
+
+       [ -x ${BACDIRBIN}/bacula-dir ] && { 
+          sleep 2
+          echo "Starting the Bacula Director daemon"
+         OPTIONS=''
+         if [ "${DIR_USER}" != '' ]; then
+            OPTIONS="${OPTIONS} -u ${DIR_USER}"
+         fi
+
+         if [ "${DIR_GROUP}" != '' ]; then
+            OPTIONS="${OPTIONS} -g ${DIR_GROUP}"
+         fi
+
+         ${BACDIRBIN}/bacula-dir $2 ${OPTIONS} -v -c ${BACDIRCFG}/bacula-dir.conf
+       }
        ;;
+
     stop)
-       echo "Stopping the File daemon"
-       killproc @sbindir@/bacula-fd @fd_port@
-       echo "Stopping the Storage daemon"
-       killproc @sbindir@/bacula-sd @sd_port@
-       echo "Stopping the Director daemon"
-       killproc @sbindir@/bacula-dir @dir_port@
+       # Stop the FD first so that SD will fail jobs and update catalog
+       [ -x ${BACFDBIN}/bacula-fd ] && {
+         echo "Stopping the Bacula File daemon"
+         killproc ${BACFDBIN}/bacula-fd ${FD_PORT}
+       }
+
+       [ -x ${BACSDBIN}/bacula-sd ] && {
+         echo "Stopping the Bacula Storage daemon"
+         killproc ${BACSDBIN}/bacula-sd ${SD_PORT}
+       }
+
+       [ -x ${BACDIRBIN}/bacula-dir ] && {
+         echo "Stopping the Bacula Director daemon"
+         killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT}
+       }
        echo
        ;;
+
     restart)
        $0 stop
        sleep 5
        $0 start
        ;;
+
     status)
-       status @sbindir@/bacula-sd @sd_port@
-       status @sbindir@/bacula-fd @fd_port@
-       status @sbindir@/bacula-dir @dir_port@
+       [ -x ${BACSDBIN}/bacula-sd   ] && status ${BACSDBIN}/bacula-sd  ${SD_PORT}
+       [ -x ${BACFDBIN}/bacula-fd   ] && status ${BACFDBIN}/bacula-fd  ${FD_PORT}
+       [ -x ${BACDIRBIN}/bacula-dir ] && status ${BACDIRBIN}/bacula-dir ${DIR_PORT}
        ;;
+
     *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1