From 2a01e1677f1f6309935603e82156f074420503ab Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 25 Mar 2006 13:35:28 +0000 Subject: [PATCH] Split the bacula start/start script into four files: bacula -- starts and stops calling other scripts bacula-ctl-dir -- starts/stops the director bacula-ctl-fd -- starts/stops the File daemon bacula-ctl-sd -- starts/stops the Storage daemon git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2853 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/autoconf/configure.in | 3 + bacula/configure | 5 +- bacula/kes-1.38 | 6 + bacula/scripts/.cvsignore | 3 + bacula/scripts/Makefile.in | 9 ++ bacula/scripts/bacula-ctl-dir.in | 237 +++++++++++++++++++++++++++++ bacula/scripts/bacula-ctl-fd.in | 237 +++++++++++++++++++++++++++++ bacula/scripts/bacula-ctl-sd.in | 237 +++++++++++++++++++++++++++++ bacula/scripts/bacula-dir.sh.in | 0 bacula/scripts/bacula-fd.sh.in | 0 bacula/scripts/bacula-sd.sh.in | 0 bacula/scripts/bacula.in | 252 ++----------------------------- 12 files changed, 745 insertions(+), 244 deletions(-) create mode 100644 bacula/scripts/bacula-ctl-dir.in create mode 100644 bacula/scripts/bacula-ctl-fd.in create mode 100644 bacula/scripts/bacula-ctl-sd.in create mode 100644 bacula/scripts/bacula-dir.sh.in create mode 100644 bacula/scripts/bacula-fd.sh.in create mode 100644 bacula/scripts/bacula-sd.sh.in diff --git a/bacula/autoconf/configure.in b/bacula/autoconf/configure.in index 984b356e95..b8b0012f6c 100644 --- a/bacula/autoconf/configure.in +++ b/bacula/autoconf/configure.in @@ -1921,6 +1921,9 @@ AC_OUTPUT([autoconf/Make.common \ scripts/bconsole \ scripts/gconsole \ scripts/bacula \ + scripts/bacula-ctl-dir \ + scripts/bacula-ctl-fd \ + scripts/bacula-ctl-sd \ scripts/devel_bacula \ scripts/Makefile \ scripts/logrotate \ diff --git a/bacula/configure b/bacula/configure index 6adc9896de..a31d0fd27a 100755 --- a/bacula/configure +++ b/bacula/configure @@ -29834,7 +29834,7 @@ if test "x${subsysdir}" = "x${sbindir}" ; then exit 1 fi - ac_config_files="$ac_config_files autoconf/Make.common Makefile scripts/startmysql scripts/stopmysql scripts/btraceback scripts/startit scripts/stopit scripts/bconsole scripts/gconsole scripts/bacula scripts/devel_bacula scripts/Makefile scripts/logrotate scripts/bacula.desktop.gnome1 scripts/bacula.desktop.gnome2 scripts/bacula.desktop.gnome1.consolehelper scripts/bacula.desktop.gnome2.consolehelper scripts/bacula.desktop.gnome1.xsu scripts/bacula.desktop.gnome2.xsu scripts/gnome-console.console_apps scripts/mtx-changer scripts/disk-changer scripts/dvd-handler scripts/bacula-tray-monitor.desktop scripts/logwatch/Makefile scripts/logwatch/logfile.bacula.conf src/Makefile src/host.h src/console/Makefile src/console/bconsole.conf src/gnome2-console/Makefile src/gnome2-console/gnome-console.conf src/wx-console/Makefile src/wx-console/wx-console.conf src/tray-monitor/Makefile src/tray-monitor/tray-monitor.conf src/dird/Makefile src/dird/bacula-dir.conf src/lib/Makefile src/stored/Makefile src/stored/bacula-sd.conf src/filed/Makefile src/filed/bacula-fd.conf src/filed/win32/Makefile src/cats/Makefile src/cats/make_catalog_backup src/cats/delete_catalog_backup src/cats/create_postgresql_database src/cats/update_postgresql_tables src/cats/make_postgresql_tables src/cats/grant_postgresql_privileges src/cats/drop_postgresql_tables src/cats/drop_postgresql_database src/cats/create_mysql_database src/cats/update_mysql_tables src/cats/make_mysql_tables src/cats/grant_mysql_privileges src/cats/drop_mysql_tables src/cats/drop_mysql_database src/cats/create_sqlite_database src/cats/update_sqlite_tables src/cats/make_sqlite_tables src/cats/grant_sqlite_privileges src/cats/drop_sqlite_tables src/cats/drop_sqlite_database src/cats/create_sqlite3_database src/cats/update_sqlite3_tables src/cats/make_sqlite3_tables src/cats/grant_sqlite3_privileges src/cats/drop_sqlite3_tables src/cats/drop_sqlite3_database src/cats/sqlite src/cats/mysql src/cats/create_bdb_database src/cats/update_bdb_tables src/cats/make_bdb_tables src/cats/grant_bdb_privileges src/cats/drop_bdb_tables src/cats/drop_bdb_database src/cats/create_bacula_database src/cats/update_bacula_tables src/cats/grant_bacula_privileges src/cats/make_bacula_tables src/cats/drop_bacula_tables src/cats/drop_bacula_database src/findlib/Makefile src/pygtk-console/Makefile src/tools/Makefile src/win32/winbacula.nsi src/win32/baculafd/bacula-fd.conf src/win32/Makefile src/win32/console/bconsole.conf src/win32/wx-console/wx-console.conf src/win32/pebuilder/Makefile po/Makefile.in $PFILES" + ac_config_files="$ac_config_files autoconf/Make.common Makefile scripts/startmysql scripts/stopmysql scripts/btraceback scripts/startit scripts/stopit scripts/bconsole scripts/gconsole scripts/bacula scripts/bacula-ctl-dir scripts/bacula-ctl-fd scripts/bacula-ctl-sd scripts/devel_bacula scripts/Makefile scripts/logrotate scripts/bacula.desktop.gnome1 scripts/bacula.desktop.gnome2 scripts/bacula.desktop.gnome1.consolehelper scripts/bacula.desktop.gnome2.consolehelper scripts/bacula.desktop.gnome1.xsu scripts/bacula.desktop.gnome2.xsu scripts/gnome-console.console_apps scripts/mtx-changer scripts/disk-changer scripts/dvd-handler scripts/bacula-tray-monitor.desktop scripts/logwatch/Makefile scripts/logwatch/logfile.bacula.conf src/Makefile src/host.h src/console/Makefile src/console/bconsole.conf src/gnome2-console/Makefile src/gnome2-console/gnome-console.conf src/wx-console/Makefile src/wx-console/wx-console.conf src/tray-monitor/Makefile src/tray-monitor/tray-monitor.conf src/dird/Makefile src/dird/bacula-dir.conf src/lib/Makefile src/stored/Makefile src/stored/bacula-sd.conf src/filed/Makefile src/filed/bacula-fd.conf src/filed/win32/Makefile src/cats/Makefile src/cats/make_catalog_backup src/cats/delete_catalog_backup src/cats/create_postgresql_database src/cats/update_postgresql_tables src/cats/make_postgresql_tables src/cats/grant_postgresql_privileges src/cats/drop_postgresql_tables src/cats/drop_postgresql_database src/cats/create_mysql_database src/cats/update_mysql_tables src/cats/make_mysql_tables src/cats/grant_mysql_privileges src/cats/drop_mysql_tables src/cats/drop_mysql_database src/cats/create_sqlite_database src/cats/update_sqlite_tables src/cats/make_sqlite_tables src/cats/grant_sqlite_privileges src/cats/drop_sqlite_tables src/cats/drop_sqlite_database src/cats/create_sqlite3_database src/cats/update_sqlite3_tables src/cats/make_sqlite3_tables src/cats/grant_sqlite3_privileges src/cats/drop_sqlite3_tables src/cats/drop_sqlite3_database src/cats/sqlite src/cats/mysql src/cats/create_bdb_database src/cats/update_bdb_tables src/cats/make_bdb_tables src/cats/grant_bdb_privileges src/cats/drop_bdb_tables src/cats/drop_bdb_database src/cats/create_bacula_database src/cats/update_bacula_tables src/cats/grant_bacula_privileges src/cats/make_bacula_tables src/cats/drop_bacula_tables src/cats/drop_bacula_database src/findlib/Makefile src/pygtk-console/Makefile src/tools/Makefile src/win32/winbacula.nsi src/win32/baculafd/bacula-fd.conf src/win32/Makefile src/win32/console/bconsole.conf src/win32/wx-console/wx-console.conf src/win32/pebuilder/Makefile po/Makefile.in $PFILES" ac_config_commands="$ac_config_commands default" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -30387,6 +30387,9 @@ do "scripts/bconsole" ) CONFIG_FILES="$CONFIG_FILES scripts/bconsole" ;; "scripts/gconsole" ) CONFIG_FILES="$CONFIG_FILES scripts/gconsole" ;; "scripts/bacula" ) CONFIG_FILES="$CONFIG_FILES scripts/bacula" ;; + "scripts/bacula-ctl-dir" ) CONFIG_FILES="$CONFIG_FILES scripts/bacula-ctl-dir" ;; + "scripts/bacula-ctl-fd" ) CONFIG_FILES="$CONFIG_FILES scripts/bacula-ctl-fd" ;; + "scripts/bacula-ctl-sd" ) CONFIG_FILES="$CONFIG_FILES scripts/bacula-ctl-sd" ;; "scripts/devel_bacula" ) CONFIG_FILES="$CONFIG_FILES scripts/devel_bacula" ;; "scripts/Makefile" ) CONFIG_FILES="$CONFIG_FILES scripts/Makefile" ;; "scripts/logrotate" ) CONFIG_FILES="$CONFIG_FILES scripts/logrotate" ;; diff --git a/bacula/kes-1.38 b/bacula/kes-1.38 index 1223879a83..aec4edd730 100644 --- a/bacula/kes-1.38 +++ b/bacula/kes-1.38 @@ -2,6 +2,12 @@ Kern Sibbald General: +25Mar06 +- Split the bacula start/start script into four files: + bacula -- starts and stops calling other scripts + bacula-ctl-dir -- starts/stops the director + bacula-ctl-fd -- starts/stops the File daemon + bacula-ctl-sd -- starts/stops the Storage daemon 24Mar06 - Create datestyle fix for PostgreSQL. Fixes bug #574. - Correct editing of JobId from int to int64 in fd_cmds.c diff --git a/bacula/scripts/.cvsignore b/bacula/scripts/.cvsignore index e39d44a262..38595022c1 100644 --- a/bacula/scripts/.cvsignore +++ b/bacula/scripts/.cvsignore @@ -24,3 +24,6 @@ bacula.desktop.gnome2.xsu bacula.desktop.gnome2.consolehelper bacula.desktop.gnome1.xsu bacula.desktop.gnome1.consolehelper +bacula-ctl-dir +bacula-ctl-fd +bacula-ctl-sd diff --git a/bacula/scripts/Makefile.in b/bacula/scripts/Makefile.in index 1bf17739fc..19aa7e3f96 100755 --- a/bacula/scripts/Makefile.in +++ b/bacula/scripts/Makefile.in @@ -38,6 +38,9 @@ install: installdirs $(INSTALL_SCRIPT) bconsole $(DESTDIR)$(scriptdir)/bconsole $(INSTALL_SCRIPT) gconsole $(DESTDIR)$(scriptdir)/gconsole $(INSTALL_SCRIPT) bacula $(DESTDIR)$(scriptdir)/bacula + $(INSTALL_SCRIPT) bacula-ctl-dir $(DESTDIR)$(scriptdir)/bacula-ctl-dir + $(INSTALL_SCRIPT) bacula-ctl-fd $(DESTDIR)$(scriptdir)/bacula-ctl-fd + $(INSTALL_SCRIPT) bacula-ctl-sd $(DESTDIR)$(scriptdir)/bacula-ctl-sd @if test -f ${DESTDIR}${scriptdir}/mtx-changer; then \ echo " ==> Saving existing mtx-changer to mtx-changer.old"; \ $(MV) -f ${DESTDIR}${scriptdir}/mtx-changer ${DESTDIR}${scriptdir}/mtx-changer.old; \ @@ -69,6 +72,9 @@ uninstall: (cd $(DESTDIR)$(scriptdir); $(RMF) bconsole) (cd $(DESTDIR)$(scriptdir); $(RMF) gconsole) (cd $(DESTDIR)$(scriptdir); $(RMF) bacula) + (cd $(DESTDIR)$(scriptdir); $(RMF) bacula-ctl-dir) + (cd $(DESTDIR)$(scriptdir); $(RMF) bacula-ctl-fd) + (cd $(DESTDIR)$(scriptdir); $(RMF) bacula-ctl-sd) (cd $(DESTDIR)$(scriptdir); $(RMF) fd) (cd $(DESTDIR)$(scriptdir); $(RMF) mtx-changer) (cd $(DESTDIR)$(scriptdir); $(RMF) disk-changer) @@ -82,11 +88,13 @@ Makefile: Makefile.in cd $(topdir) \ && CONFIG_FILES=$(thisdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status chmod 755 startmysql stopmysql bacula startit stopit btraceback + chmod 755 bacula-ctl-dir bacula-ctl-fd bacula-ctl-sd chmod 755 disk-changer mtx-changer dvd-handler bconsole gconsole Makefiles: $(SHELL) config.status chmod 755 startmysql stopmysql bacula startit stopit btraceback + chmod 755 bacula-ctl-dir bacula-ctl-fd bacula-ctl-sd chmod 755 mtx-changer dvd-handler bconsole gconsole clean: @@ -95,6 +103,7 @@ clean: # clean for distribution distclean: clean @$(RMF) startmysql stopmysql bacula fd startit stopit btraceback + @$(RMF) bacula-ctl-dir bacula-ctl-fd bacula-ctl-sd @$(RMF) bconsole gconsole logrotate bacula.desktop @$(RMF) bacula.desktop.gnome1 bacula.desktop.gnome2 mtx-changer dvd-handler @$(RMF) gnome-console.console_apps bacula.desktop.gnome2.xsu diff --git a/bacula/scripts/bacula-ctl-dir.in b/bacula/scripts/bacula-ctl-dir.in new file mode 100644 index 0000000000..a418c4ddb7 --- /dev/null +++ b/bacula/scripts/bacula-ctl-dir.in @@ -0,0 +1,237 @@ +#! /bin/sh +# +# bacula-ctl-dir This shell script takes care of starting and stopping +# the bacula Director daemon +# +# This is pretty much watered down version of the RedHat script +# that works on Solaris as well as Linux, but it won't work everywhere. +# +# description: It comes by night and sucks the vital essence from your computers. +# + +PSCMD="@PSCMD@" +PS="ps" + +# +# 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. +# +BACDIRBIN=@sbindir@ +BACDIRCFG=@sysconfdir@ +PIDDIR=@piddir@ +SUBSYSDIR=@subsysdir@ + +DIR_PORT=@dir_port@ + +DIR_USER=@dir_user@ +DIR_GROUP=@dir_group@ + +PIDOF=@PIDOF@ + +# A function to stop a program. +killproc() { + RC=0 + # Test syntax. + if [ $# = 0 ]; then + echo "Usage: killproc {program} {port} [signal]" + return 1 + fi + + notset=0 + # check for third arg to be kill level + if [ "$3" != "" ] ; then + killlevel=$3 + else + notset=1 + killlevel="-9" + fi + + # Get base program name + base=`basename $1` + + # Find pid. + pid=`pidofproc $base $2` + + # Kill it. + if [ "$pid" != "" ] ; then + if [ "$notset" = "1" ] ; then + if ${PS} -p $pid>/dev/null 2>&1; then + # TERM first, then KILL if not dead + kill -TERM $pid 2>/dev/null + sleep 1 + if ${PS} -p $pid >/dev/null 2>&1 ; then + sleep 1 + if ${PS} -p $pid >/dev/null 2>&1 ; then + sleep 3 + if ${PS} -p $pid >/dev/null 2>&1 ; then + kill -KILL $pid 2>/dev/null + fi + fi + fi + fi + ${PS} -p $pid >/dev/null 2>&1 + RC=$? + [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown" + # RC=$((! $RC)) + # use specified level only + else + if ${PS} -p $pid >/dev/null 2>&1; then + kill $killlevel $pid 2>/dev/null + RC=$? + [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel" + fi + fi + else + failure "$base shutdown" + fi + # Remove pid file if any. + if [ "$notset" = "1" ]; then + rm -f ${PIDDIR}/$base.$2.pid + fi + return $RC +} + +# A function to find the pid of a program. +pidofproc() { + pid="" + # Test syntax. + if [ $# = 0 ] ; then + echo "Usage: pidofproc {program}" + return 1 + fi + + # Get base program name + base=`basename $1` + + # First try PID file + if [ -f ${PIDDIR}/$base.$2.pid ] ; then + pid=`head -n 1 ${PIDDIR}/$base.$2.pid` + if [ "$pid" != "" ] ; then + echo $pid + return 0 + fi + fi + + # Next try "pidof" + if [ -x ${PIDOF} ] ; then + pid=`${PIDOF} $1` + fi + if [ "$pid" != "" ] ; then + echo $pid + return 0 + fi + + # Finally try to extract it from ps + ${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' ' + return 0 +} + +status() { + pid="" + # Test syntax. + if [ $# = 0 ] ; then + echo "Usage: status {program} {port}" + return 1 + fi + + # Get base program name + base=`basename $1` + + # First try "pidof" + 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 } + { if ((prog == $2) || (("(" prog ")") == $2) || + (("[" prog "]") == $2) || + ((prog ":") == $2)) { print $1 ; exit 0 } }' $1` + if [ "$pid" != "" ] ; then + echo "$base (pid $pid) is running..." + return 0 + fi + fi + + # Next try the PID files + 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 + echo "$base dead but subsys locked" + return 2 + fi + echo "$base is stopped" + return 3 +} + +success() { + return 0 +} + +failure() { + rc=$? + return $rc +} + +OS=`uname -s` + +# if /lib/tls exists, force Bacula to use the glibc pthreads instead +if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then + export LD_ASSUME_KERNEL=2.4.19 +fi + +case "$1" in + start) + [ -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) + [ -x ${BACDIRBIN}/bacula-dir ] && { + echo "Stopping the Bacula Director daemon" + killproc ${BACDIRBIN}/bacula-dir ${DIR_PORT} + } + ;; + + restart) + $0 stop + sleep 5 + $0 start + ;; + + status) + [ -x ${BACDIRBIN}/bacula-dir ] && status ${BACDIRBIN}/bacula-dir ${DIR_PORT} + ;; + + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac +exit 0 diff --git a/bacula/scripts/bacula-ctl-fd.in b/bacula/scripts/bacula-ctl-fd.in new file mode 100644 index 0000000000..6f0610074d --- /dev/null +++ b/bacula/scripts/bacula-ctl-fd.in @@ -0,0 +1,237 @@ +#! /bin/sh +# +# bacula-ctl-fd This shell script takes care of starting and stopping +# the bacula File daemon. +# +# This is pretty much watered down version of the RedHat script +# that works on Solaris as well as Linux, but it won't work everywhere. +# +# description: It comes by night and sucks the vital essence from your computers. +# + +PSCMD="@PSCMD@" +PS="ps" + +# +# 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@ +PIDDIR=@piddir@ +SUBSYSDIR=@subsysdir@ + +FD_PORT=@fd_port@ + +FD_USER=@fd_user@ +FD_GROUP=@fd_group@ + +PIDOF=@PIDOF@ + +# A function to stop a program. +killproc() { + RC=0 + # Test syntax. + if [ $# = 0 ]; then + echo "Usage: killproc {program} {port} [signal]" + return 1 + fi + + notset=0 + # check for third arg to be kill level + if [ "$3" != "" ] ; then + killlevel=$3 + else + notset=1 + killlevel="-9" + fi + + # Get base program name + base=`basename $1` + + # Find pid. + pid=`pidofproc $base $2` + + # Kill it. + if [ "$pid" != "" ] ; then + if [ "$notset" = "1" ] ; then + if ${PS} -p $pid>/dev/null 2>&1; then + # TERM first, then KILL if not dead + kill -TERM $pid 2>/dev/null + sleep 1 + if ${PS} -p $pid >/dev/null 2>&1 ; then + sleep 1 + if ${PS} -p $pid >/dev/null 2>&1 ; then + sleep 3 + if ${PS} -p $pid >/dev/null 2>&1 ; then + kill -KILL $pid 2>/dev/null + fi + fi + fi + fi + ${PS} -p $pid >/dev/null 2>&1 + RC=$? + [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown" + # RC=$((! $RC)) + # use specified level only + else + if ${PS} -p $pid >/dev/null 2>&1; then + kill $killlevel $pid 2>/dev/null + RC=$? + [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel" + fi + fi + else + failure "$base shutdown" + fi + # Remove pid file if any. + if [ "$notset" = "1" ]; then + rm -f ${PIDDIR}/$base.$2.pid + fi + return $RC +} + +# A function to find the pid of a program. +pidofproc() { + pid="" + # Test syntax. + if [ $# = 0 ] ; then + echo "Usage: pidofproc {program}" + return 1 + fi + + # Get base program name + base=`basename $1` + + # First try PID file + if [ -f ${PIDDIR}/$base.$2.pid ] ; then + pid=`head -n 1 ${PIDDIR}/$base.$2.pid` + if [ "$pid" != "" ] ; then + echo $pid + return 0 + fi + fi + + # Next try "pidof" + if [ -x ${PIDOF} ] ; then + pid=`${PIDOF} $1` + fi + if [ "$pid" != "" ] ; then + echo $pid + return 0 + fi + + # Finally try to extract it from ps + ${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' ' + return 0 +} + +status() { + pid="" + # Test syntax. + if [ $# = 0 ] ; then + echo "Usage: status {program} {port}" + return 1 + fi + + # Get base program name + base=`basename $1` + + # First try "pidof" + 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 } + { if ((prog == $2) || (("(" prog ")") == $2) || + (("[" prog "]") == $2) || + ((prog ":") == $2)) { print $1 ; exit 0 } }' $1` + if [ "$pid" != "" ] ; then + echo "$base (pid $pid) is running..." + return 0 + fi + fi + + # Next try the PID files + 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 + echo "$base dead but subsys locked" + return 2 + fi + echo "$base is stopped" + return 3 +} + +success() { + return 0 +} + +failure() { + rc=$? + return $rc +} + +OS=`uname -s` + +# if /lib/tls exists, force Bacula to use the glibc pthreads instead +if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then + export LD_ASSUME_KERNEL=2.4.19 +fi + +case "$1" in + start) + [ -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 + } + ;; + + stop) + # 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} + } + ;; + + restart) + $0 stop + sleep 5 + $0 start + ;; + + status) + [ -x ${BACFDBIN}/bacula-fd ] && status ${BACFDBIN}/bacula-fd ${FD_PORT} + ;; + + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac +exit 0 diff --git a/bacula/scripts/bacula-ctl-sd.in b/bacula/scripts/bacula-ctl-sd.in new file mode 100644 index 0000000000..d918cbcbe5 --- /dev/null +++ b/bacula/scripts/bacula-ctl-sd.in @@ -0,0 +1,237 @@ +#! /bin/sh +# +# bacula-ctl-sd This shell script takes care of starting and stopping +# the bacula Storage daemon +# +# This is pretty much watered down version of the RedHat script +# that works on Solaris as well as Linux, but it won't work everywhere. +# +# description: It comes by night and sucks the vital essence from your computers. +# + +PSCMD="@PSCMD@" +PS="ps" + +# +# 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. +# +BACSDBIN=@sbindir@ +BACSDCFG=@sysconfdir@ +PIDDIR=@piddir@ +SUBSYSDIR=@subsysdir@ + +SD_PORT=@sd_port@ + +SD_USER=@sd_user@ +SD_GROUP=@sd_group@ + +PIDOF=@PIDOF@ + +# A function to stop a program. +killproc() { + RC=0 + # Test syntax. + if [ $# = 0 ]; then + echo "Usage: killproc {program} {port} [signal]" + return 1 + fi + + notset=0 + # check for third arg to be kill level + if [ "$3" != "" ] ; then + killlevel=$3 + else + notset=1 + killlevel="-9" + fi + + # Get base program name + base=`basename $1` + + # Find pid. + pid=`pidofproc $base $2` + + # Kill it. + if [ "$pid" != "" ] ; then + if [ "$notset" = "1" ] ; then + if ${PS} -p $pid>/dev/null 2>&1; then + # TERM first, then KILL if not dead + kill -TERM $pid 2>/dev/null + sleep 1 + if ${PS} -p $pid >/dev/null 2>&1 ; then + sleep 1 + if ${PS} -p $pid >/dev/null 2>&1 ; then + sleep 3 + if ${PS} -p $pid >/dev/null 2>&1 ; then + kill -KILL $pid 2>/dev/null + fi + fi + fi + fi + ${PS} -p $pid >/dev/null 2>&1 + RC=$? + [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown" + # RC=$((! $RC)) + # use specified level only + else + if ${PS} -p $pid >/dev/null 2>&1; then + kill $killlevel $pid 2>/dev/null + RC=$? + [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel" + fi + fi + else + failure "$base shutdown" + fi + # Remove pid file if any. + if [ "$notset" = "1" ]; then + rm -f ${PIDDIR}/$base.$2.pid + fi + return $RC +} + +# A function to find the pid of a program. +pidofproc() { + pid="" + # Test syntax. + if [ $# = 0 ] ; then + echo "Usage: pidofproc {program}" + return 1 + fi + + # Get base program name + base=`basename $1` + + # First try PID file + if [ -f ${PIDDIR}/$base.$2.pid ] ; then + pid=`head -n 1 ${PIDDIR}/$base.$2.pid` + if [ "$pid" != "" ] ; then + echo $pid + return 0 + fi + fi + + # Next try "pidof" + if [ -x ${PIDOF} ] ; then + pid=`${PIDOF} $1` + fi + if [ "$pid" != "" ] ; then + echo $pid + return 0 + fi + + # Finally try to extract it from ps + ${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' ' + return 0 +} + +status() { + pid="" + # Test syntax. + if [ $# = 0 ] ; then + echo "Usage: status {program} {port}" + return 1 + fi + + # Get base program name + base=`basename $1` + + # First try "pidof" + 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 } + { if ((prog == $2) || (("(" prog ")") == $2) || + (("[" prog "]") == $2) || + ((prog ":") == $2)) { print $1 ; exit 0 } }' $1` + if [ "$pid" != "" ] ; then + echo "$base (pid $pid) is running..." + return 0 + fi + fi + + # Next try the PID files + 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 + echo "$base dead but subsys locked" + return 2 + fi + echo "$base is stopped" + return 3 +} + +success() { + return 0 +} + +failure() { + rc=$? + return $rc +} + +OS=`uname -s` + +# if /lib/tls exists, force Bacula to use the glibc pthreads instead +if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then + export LD_ASSUME_KERNEL=2.4.19 +fi + +case "$1" in + start) + [ -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 + } + ;; + + + stop) + [ -x ${BACSDBIN}/bacula-sd ] && { + echo "Stopping the Bacula Storage daemon" + killproc ${BACSDBIN}/bacula-sd ${SD_PORT} + } + ;; + + restart) + $0 stop + sleep 5 + $0 start + ;; + + status) + [ -x ${BACSDBIN}/bacula-sd ] && status ${BACSDBIN}/bacula-sd ${SD_PORT} + ;; + + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac +exit 0 diff --git a/bacula/scripts/bacula-dir.sh.in b/bacula/scripts/bacula-dir.sh.in new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bacula/scripts/bacula-fd.sh.in b/bacula/scripts/bacula-fd.sh.in new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bacula/scripts/bacula-sd.sh.in b/bacula/scripts/bacula-sd.sh.in new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bacula/scripts/bacula.in b/bacula/scripts/bacula.in index 8aa6b5c5d8..9b0c2253ab 100755 --- a/bacula/scripts/bacula.in +++ b/bacula/scripts/bacula.in @@ -9,15 +9,6 @@ # description: It comes by night and sucks the vital essence from your computers. # -PSCMD="@PSCMD@" -PS="ps" - -# -# 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. @@ -28,244 +19,19 @@ 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 - # Test syntax. - if [ $# = 0 ]; then - echo "Usage: killproc {program} {port} [signal]" - return 1 - fi - - notset=0 - # check for third arg to be kill level - if [ "$3" != "" ] ; then - killlevel=$3 - else - notset=1 - killlevel="-9" - fi - - # Get base program name - base=`basename $1` - - # Find pid. - pid=`pidofproc $base $2` - - # Kill it. - if [ "$pid" != "" ] ; then - if [ "$notset" = "1" ] ; then - if ${PS} -p $pid>/dev/null 2>&1; then - # TERM first, then KILL if not dead - kill -TERM $pid 2>/dev/null - sleep 1 - if ${PS} -p $pid >/dev/null 2>&1 ; then - sleep 1 - if ${PS} -p $pid >/dev/null 2>&1 ; then - sleep 3 - if ${PS} -p $pid >/dev/null 2>&1 ; then - kill -KILL $pid 2>/dev/null - fi - fi - fi - fi - ${PS} -p $pid >/dev/null 2>&1 - RC=$? - [ $RC -eq 0 ] && failure "$base shutdown" || success "$base shutdown" - # RC=$((! $RC)) - # use specified level only - else - if ${PS} -p $pid >/dev/null 2>&1; then - kill $killlevel $pid 2>/dev/null - RC=$? - [ $RC -eq 0 ] && success "$base $killlevel" || failure "$base $killlevel" - fi - fi - else - failure "$base shutdown" - fi - # Remove pid file if any. - if [ "$notset" = "1" ]; then - rm -f ${PIDDIR}/$base.$2.pid - fi - return $RC -} - -# A function to find the pid of a program. -pidofproc() { - pid="" - # Test syntax. - if [ $# = 0 ] ; then - echo "Usage: pidofproc {program}" - return 1 - fi - - # Get base program name - base=`basename $1` - - # First try PID file - if [ -f ${PIDDIR}/$base.$2.pid ] ; then - pid=`head -n 1 ${PIDDIR}/$base.$2.pid` - if [ "$pid" != "" ] ; then - echo $pid - return 0 - fi - fi - - # Next try "pidof" - if [ -x ${PIDOF} ] ; then - pid=`${PIDOF} $1` - fi - if [ "$pid" != "" ] ; then - echo $pid - return 0 - fi - - # Finally try to extract it from ps - ${PSCMD} | grep $1 | ${AWK} '{ print $1 }' | tr '\n' ' ' - return 0 -} - -status() { - pid="" - # Test syntax. - if [ $# = 0 ] ; then - echo "Usage: status {program} {port}" - return 1 - fi - - # Get base program name - base=`basename $1` - - # First try "pidof" - 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 } - { if ((prog == $2) || (("(" prog ")") == $2) || - (("[" prog "]") == $2) || - ((prog ":") == $2)) { print $1 ; exit 0 } }' $1` - if [ "$pid" != "" ] ; then - echo "$base (pid $pid) is running..." - return 0 - fi - fi - - # Next try the PID files - 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 - echo "$base dead but subsys locked" - return 2 - fi - echo "$base is stopped" - return 3 -} - -success() { - return 0 -} - -failure() { - rc=$? - return $rc -} - -OS=`uname -s` - -# if /lib/tls exists, force Bacula to use the glibc pthreads instead -if [ -d "/lib/tls" -a $OS = "Linux" -a `uname -r | cut -c1-3` = "2.4" ] ; then - export LD_ASSUME_KERNEL=2.4.19 -fi case "$1" in start) - [ -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 - } + [ -x ${BACSDBIN}/bacula-ctl-sd ] && ${BACSDBIN}/bacula-ctl-sd $1 $2 + [ -x ${BACFDBIN}/bacula-ctl-fd ] && ${BACFDBIN}/bacula-ctl-fd $1 $2 + [ -x ${BACDIRBIN}/bacula-ctl-dir ] && ${BACDIRBIN}/bacula-ctl-dir $1 $2 ;; stop) # 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} - } + [ -x ${BACFDBIN}/bacula-ctl-fd ] && ${BACFDBIN}/bacula-ctl-fd $1 $2 + [ -x ${BACSDBIN}/bacula-ctl-sd ] && ${BACSDBIN}/bacula-ctl-sd $1 $2 + [ -x ${BACDIRBIN}/bacula-ctl-dir ] && ${BACDIRBIN}/bacula-ctl-dir $1 $2 echo ;; @@ -276,9 +42,9 @@ case "$1" in ;; status) - [ -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} + [ -x ${BACSDBIN}/bacula-ctl-sd ] && ${BACSDBIN}/bacula-ctl-sd status + [ -x ${BACFDBIN}/bacula-ctl-fd ] && ${BACFDBIN}/bacula-ctl-fd status + [ -x ${BACDIRBIN}/bacula-ctl-dir ] && ${BACDIRBIN}/bacula-ctl-dir status ;; *) -- 2.39.5