Skip to content

Commit

Permalink
check cfg and db conn before startup of director
Browse files Browse the repository at this point in the history
We now use the possibilty to check the configuration
and database connection on startup of the director before
we really startup the daemon so that we get direct
feedback if something is wrong.

Before, we did not get any feedback because the director
forked so problems only were visible in the logfile.

Without systemd, we get the output directly, with systemd we
need to call "systemctl status bareos-dir.service"

Fixes #286: Alter the startscripts to run the daemons with -t before starting them

Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>
  • Loading branch information
pstorz authored and Marco van Wieringen committed Feb 17, 2015
1 parent 94a5502 commit 7b73791
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
16 changes: 16 additions & 0 deletions platforms/debian/bareos-dir.in
Expand Up @@ -44,6 +44,21 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that checks if the configuration is OK and
# the Database can be connected
#

checkcfg() {
echo "Checking Configuration and Database connection ... "
su -s /bin/sh $DAEMON_USER -c "@sbindir@/bareos-dir -f -t -c @sysconfdir@/bareos-dir.conf"
if [ $? -eq 0 ]; then
return 0
else
return 1
fi
}

#
# Function that starts the daemon/service
#
Expand All @@ -53,6 +68,7 @@ do_start()
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
checkcfg || return 2
start-stop-daemon --start --quiet --pidfile $PIDFILE $DAEMON_USERGROUP --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE $DAEMON_USERGROUP --exec $DAEMON -- \
Expand Down
29 changes: 22 additions & 7 deletions platforms/redhat/bareos-dir.in
Expand Up @@ -31,17 +31,32 @@ fi
MALLOC_CHECK_=0
export MALLOC_CHECK_

function checkcfg () {
echo "Checking Configuration and Database connection ... "
su -s /bin/sh ${DIR_USER} -c "@sbindir@/bareos-dir -f -t -c @sysconfdir@/bareos-dir.conf"
if [ $? -eq 0 ]; then
return 0
else
return 1
fi
}

RETVAL=0
case "$1" in
start)
if [ "${DIR_GROUP}" != '' ]; then
DIR_OPTIONS="${DIR_OPTIONS} -g ${DIR_GROUP}"
checkcfg
if [ $? -eq 0 ]; then
if [ "${DIR_GROUP}" != '' ]; then
DIR_OPTIONS="${DIR_OPTIONS} -g ${DIR_GROUP}"
fi
echo -n "Starting Bareos Director services: "
daemon --user ${DIR_USER} @sbindir@/bareos-dir $2 ${DIR_OPTIONS} -c @sysconfdir@/bareos-dir.conf
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch @subsysdir@/bareos-dira
else
echo "Configuration check failed, please check log file for errors"
fi
echo -n "Starting Bareos Director services: "
daemon --user ${DIR_USER} @sbindir@/bareos-dir $2 ${DIR_OPTIONS} -c @sysconfdir@/bareos-dir.conf
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch @subsysdir@/bareos-dir
;;
stop)
echo -n "Stopping Bareos Director services: "
Expand Down
25 changes: 21 additions & 4 deletions platforms/suse/bareos-dir.in
Expand Up @@ -12,7 +12,8 @@
# Added rc.status functions 3/13/2004 D. Scott Barninger <barninger at fairfieldcomputers.com>
# Added LSB init info 10/14/2004 D. Scott Barninger <barninger at fairfieldcomputers.com>
# Added $remote_fs, add bareos specific daemon user & group Bruno Friedmann <bruno@ioda-net.ch>
#
# Added config check Philipp Storz <Philipp.Storz@bareos.com>

### BEGIN INIT INFO
# Provides: bareos-dir
# Required-Start: $local_fs $remote_fs $network $time $syslog
Expand All @@ -29,12 +30,28 @@
# this gives us funtion rc_status -v to tell us if we succeed or fail
. /etc/rc.status

function checkcfg () {
echo "Checking Configuration and Database connection ... "
su -s /bin/sh @dir_user@ -c "@sbindir@/bareos-dir -f -t -c @sysconfdir@/bareos-dir.conf"
if [ $? -eq 0 ]; then
return 0
else
return 1
fi
}

RETVAL=0
case "$1" in
start)
echo -n "Starting the Bareos Director: "
/sbin/startproc -u @dir_user@ -g @dir_group@ @sbindir@/bareos-dir $2 -c @sysconfdir@/bareos-dir.conf
rc_status -v && touch @subsysdir@/bareos-dir
checkcfg
if [ $? -eq 0 ]; then
echo -n "Starting the Bareos Director: "
/sbin/startproc -u @dir_user@ -g @dir_group@ @sbindir@/bareos-dir $2 -c @sysconfdir@/bareos-dir.conf
rc_status -v && touch @subsysdir@/bareos-dir
else
echo "Configuration check failed, please check log file for errors"
rc_failed
fi
;;
stop)
echo -n "Stopping the Director daemon: "
Expand Down
5 changes: 3 additions & 2 deletions platforms/systemd/bareos-dir.service.in
Expand Up @@ -31,11 +31,12 @@ Group=@dir_group@
WorkingDirectory=@working_dir@
PIDFile=@piddir@/bareos-dir.@dir_port@.pid
# EnvironmentFile=-/etc/sysconfig/bareos-dir
StandardOutput=syslog
# StandardOutput=syslog
ExecStartPre=@sbindir@/bareos-dir -c @sysconfdir@/bareos-dir.conf -t -f
ExecStart=@sbindir@/bareos-dir -c @sysconfdir@/bareos-dir.conf
# This daemon should be able to reload the conf file
#ExecReload=/sbin/killproc -p @piddir@/bareos-dir.pid -HUP @sbindir@/bareos-dir
Restart=on-failure
#Restart=on-failure

[Install]
WantedBy=multi-user.target

0 comments on commit 7b73791

Please sign in to comment.