On 12/01/17 16:17, Charles wrote:
...
> To be thorough, the bacula-sd init script should not only run the mt
> rewoffl and mtx unload commands; it should also error trap their output.
> I suspect that, when our autoloader and backup server are powered up at
> the same time, the autoloader does not finish initialising before the
> backup server runs the bacula-sd init script. In which case the mt and
> mtx commands are ineffective and SD finds a tape in the drive resulting
> in the tape getting Bacula status Error.
>
> More after I have tested error trapping the mt rewoffl and mtx unload
> commands.
Here's my solution. Beware of line wraps.
[email protected]:~# diff -u /etc/init.d/bacula-sd{.org,}
--- /etc/init.d/bacula-sd.org 2016-08-17 16:15:12.000000000 +0530
+++ /etc/init.d/bacula-sd 2017-01-15 20:08:37.125034780 +0530
@@ -20,6 +20,10 @@
# Customized for Bacula by Jose Luis Tallon
<jltallon AT adv-solutions DOT net>
#
+# 15 Jan 2017 Charles for Support #3484 "autoloader1.iciti.av: cartridge
+# AS0008L6: media error"
+# * Added AUTOLOADER_INIT
+
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin
@@ -42,6 +46,7 @@
CONFIG="${CONFIG:-/etc/bacula/$NAME.conf}"
STOPTIMEOUT="${STOPTIMEOUT:-180}"
+AUTOLOADER_INIT="${AUTOLOADER_INIT:-/usr/local/etc/init.d/bacula-sd-autoloader}"
create_var_run_dir
@@ -50,6 +55,15 @@
do_start()
{
if $DAEMON -t -c $CONFIG $ARGS > /dev/null 2>&1; then
+ if [ -x "$AUTOLOADER_INIT" ]; then
+ log_progress_msg "- running $AUTOLOADER_INIT"
+ "$AUTOLOADER_INIT"
+ if [ $? != 0 ]]; then
+ log_failure_msg \
+ "Not starting $DESC: could not initialise autoloader"
+ return 1
+ fi
+ fi
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--oknodo --exec $DAEMON -- -c $CONFIG $ARGS
return 0
[email protected]:~# cat /usr/local/etc/init.d/bacula-sd-autoloader
#!/bin/bash
# Copyright (C) 2017 Charles Atkinson
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# Helper script for /etc/init.d/bacula-sd.
# Ensures the autoloader is suitably initialised
# Usage:
# * No arguments or options
# * Configuration by /etc/default/bacula-sd-autoloader
# * Intended to be called by /etc/init.d/bacula-sd
# * /etc/init.d/bacula-sd should fail if this script returns non-zero
# 15 Jan 2017 Charles Atkinson
# * Creation
# Do nothing if bacula-sd is already running
netstat -plnt | grep -q bacula-sd && exit 0
# Configuration
PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=bacula-sd-autoloader
. /lib/lsb/init-functions
if [[ -r /etc/default/$NAME ]]; then
. /etc/default/$NAME
else
log_failure_msg "Not initalising autoloader: /etc/default/$NAME
does not exist"
exit 1
fi
if [[ $AUTOLOADER_DEV = '' ]]; then
log_failure_msg "Not initalising autoloader: /etc/default/$NAME did
not set AUTOLOADER_DEV"
exit 1
fi
if [[ $TAPE_DEV = '' ]]; then
log_failure_msg "Not initalising autoloader: /etc/default/$NAME did
not set TAPE_DEV"
exit 1
fi
TIMEOUT=${TIMEOUT:60}
# Initialise the autoloader
declare -r rewoffl_OK_regex='^$|rmtopen failed: No medium found$'
declare -r unload_OK_regex='^(Unloading drive 0 into Storage Element
[[:digit:]]\.+done|Data Transfer Element 0 is Empty)$'
start_time=$(date +%s)
while true
do
err_count=0
err_msg=
buf=$(mt -f "$TAPE_DEV" rewoffl 2>&1)
if [[ ! $buf =~ $rewoffl_OK_regex ]]; then
err_msg+=$'\n'$buf
((err_count++))
fi
buf=$(mtx -f "$AUTOLOADER_DEV" unload 2>&1)
if [[ ! $buf =~ $unload_OK_regex ]]; then
err_msg+=$'\n'$buf
((err_count++))
fi
((err_count==0)) && break
now_time=$(date +%s)
if ((now_time-start_time>TIMEOUT)); then
log_failure_msg "Unable to initalise autoloader: $err_msg"
exit 1
fi
done
exit 0
[email protected]:~# cat /etc/default/bacula-sd-autoloader
# Configuration sccript for /usr/local/etc/init.d/bacula-sd-autoloader
# Required conf values
AUTOLOADER_DEV=/dev/sg5
TAPE_DEV=/dev/st0
# Optional conf value
#TIMEOUT=120 # Seconds to wait for autoloader to become available.
Default 60
Best
Charles
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users
|