X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Famdump.sh;h=7449dfe0eb4560e4bd60847a6572b17c812a3a0a;hb=f62188753ffc49e6b684b288dd9394f71b1e776c;hp=70a0a7f5ad289a25d28d6a967c03055bef20faf6;hpb=000f3f87bab07adbb80c7f67f11e7a984b0f3a92;p=debian%2Famanda diff --git a/server-src/amdump.sh b/server-src/amdump.sh index 70a0a7f..7449dfe 100644 --- a/server-src/amdump.sh +++ b/server-src/amdump.sh @@ -42,20 +42,9 @@ confdir=@CONFIG_DIR@ PATH="$PATH:/usr/sbin:/sbin:/usr/ucb" export PATH -USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@" -if test "$USE_VERSION_SUFFIXES" = "yes"; then - SUF="-@VERSION@" -else - SUF= -fi - if [ $# -lt 1 ] then -<<<<<<< HEAD:server-src/amdump.sh.in - echo "Usage: amdump config [host [disk...]...]" 1>&2 -======= echo `_ 'Usage: %s config [host [disk...]...]' "$0"` 1>&2 ->>>>>>> upstream:server-src/amdump.sh exit 1 fi @@ -63,23 +52,19 @@ exit_status=0; conf=$1 if [ ! -d $confdir/$conf ]; then -<<<<<<< HEAD:server-src/amdump.sh.in - echo "amdump$SUF: could not find directory $confdir/$conf" 1>&2 -======= - echo `_ '%s: could not find directory %s' "amdump$SUF" "$confdir/$conf"` 1>&2 ->>>>>>> upstream:server-src/amdump.sh + echo `_ '%s: could not find directory %s' "amdump" "$confdir/$conf"` 1>&2 exit 1 fi shift cd $confdir/$conf || exit 1 -logdir=`amgetconf$SUF $conf logdir "$@"` +logdir=`amgetconf $conf logdir "$@"` [ $? -ne 0 ] && exit 1 errfile=$logdir/amdump -tapecycle=`amgetconf$SUF $conf tapecycle "$@"` +tapecycle=`amgetconf $conf tapecycle "$@"` [ $? -ne 0 ] && exit 1 -dumpuser=`amgetconf$SUF $conf dumpuser "$@"` +dumpuser=`amgetconf $conf dumpuser "$@"` [ $? -ne 0 ] && exit 1 runuser=`{ whoami ; } 2>/dev/null` @@ -92,15 +77,6 @@ if [ $? -ne 0 ]; then fi fi -<<<<<<< HEAD:server-src/amdump.sh.in -#if [ $runuser != $dumpuser ]; then -# echo "amdump: must be run as user $dumpuser, not $runuser" 1>&2 -# exit 1 -#fi - -if test -f hold; then - echo "amdump: waiting for hold file to be removed" 1>&2 -======= if [ $runuser != $dumpuser ]; then echo `_ '%s: must be run as user %s, not %s' "$0" "$dumpuser" "$runuser"` 1>&2 exit 1 @@ -108,42 +84,15 @@ fi if test -f hold; then echo `_ '%s: waiting for hold file to be removed' "$0"` 1>&2 ->>>>>>> upstream:server-src/amdump.sh while test -f hold; do sleep 60 done fi if test -f $errfile || test -f $logdir/log; then -<<<<<<< HEAD:server-src/amdump.sh.in - echo "amdump: amdump or amflush is already running, or you must run amcleanup" 1>&2 -======= - echo `_ '%s: amdump or amflush is already running, or you must run amcleanup' "$0"` 1>&2 ->>>>>>> upstream:server-src/amdump.sh - exit 1 + amcleanup -p $conf fi -umask 077 - -exit_code=0 -# Plan and drive the dumps. -#exec $errfile 2>&1 -touch $errfile -exit_code=$? -[ $exit_code -ne 0 ] && exit_status=$exit_code -exec >$errfile 1>&2 -exit_code=$? -[ $exit_code -ne 0 ] && exit_status=$exit_code -<<<<<<< HEAD:server-src/amdump.sh.in -echo "amdump: start at `date`" -echo "amdump: datestamp `date +%Y%m%d`" -echo "amdump: starttime `date +%Y%m%d%H%M%S`" -$libexecdir/planner$SUF $conf "$@" | $libexecdir/driver$SUF $conf "$@" -exit_code=$? -[ $exit_code -ne 0 ] && exit_status=$exit_code -echo "amdump: end at `date`" -======= - gdate=`date +'%a %b %e %H:%M:%S %Z %YAAAAA%Y%m%dBBBBB%Y%m%d%H%M%SCCCCC%Y-%m-%d %H:%M:%S %Z'` #date=%a %b %e %H:%M:%S %Z %Y @@ -158,46 +107,85 @@ date_starttime=`echo $gdate |sed -e "s/^.*BBBBB//;s/CCCCC.*$//"` #date_locale_independent=%Y-%m-%d %H:%M:%S %Z date_locale_independent=`echo $gdate |sed -e "s/^.*CCCCC//"` +if test -f $errfile || test -f $logdir/log; then + process_name=`grep "^INFO .* .* pid " $logdir/log | head -n 1 | awk '{print $2}'` + echo `_ '%s: %s is already running, or you must run amcleanup' "$0" "${process_name}"` 1>&2 + echo "INFO amdump amdump pid $$" > $logdir/log.$$ + echo "START driver date $date_starttime" >> $logdir/log.$$ + echo "ERROR amdump " `_ '%s is already running, or you must run amcleanup' "${process_name}"` >> $logdir/log.$$ + $sbindir/amreport $conf --from-amdump -l $logdir/log.$$ "$@" + rm -f $logdir/log.$$ + exit 1; +fi + +umask 077 + +echo "INFO amdump amdump pid $$" > $logdir/log +exit_code=0 +# Plan and drive the dumps. +#exec $errfile 2>&1 +touch $errfile +exit_code=$? +[ $exit_code -ne 0 ] && exit_status=$exit_code +exec >$errfile 1>&2 +exit_code=$? +[ $exit_code -ne 0 ] && exit_status=$exit_code + printf '%s: start at %s\n' "amdump" "$date" printf '%s: datestamp %s\n' "amdump" "$date_datestamp" printf '%s: starttime %s\n' "amdump" "$date_starttime" printf '%s: starttime-locale-independent %s\n' "amdump" "$date_locale_independent" -$amlibexecdir/planner$SUF $conf --starttime $date_starttime "$@" | $amlibexecdir/driver$SUF $conf "$@" +if [ ! -x $amlibexecdir/planner ]; then + echo "ERROR amdump Can't execute $amlibexecdir/planner" >> $logdir/log +fi +if [ ! -x $amlibexecdir/driver ]; then + echo "ERROR amdump Can't execute $amlibexecdir/driver" >> $logdir/log +fi + +# shells don't do well with handling exit values from pipelines, so we emulate +# a pipeline in perl, in such a way that we can combine both exit statuses in a +# kind of logical "OR". +@PERL@ - $amlibexecdir/planner $amlibexecdir/driver $conf $date_starttime "$@" <<'EOPERL' +use IPC::Open3; +use POSIX qw(WIFEXITED WEXITSTATUS); +my ($planner, $driver, $conf, $date_starttime, @args) = @ARGV; + +open3("&STDERR", $planner, $conf, '--starttime', $date_starttime, @args) + or die "Could not exec $planner: $!"; +open3("<&PIPE", ">&STDOUT", ">&STDERR", $driver, $conf, @args) + or die "Could not exec $driver: $!"; + +my $first_bad_exit = 0; +for (my $i = 0; $i < 2; $i++) { + my $dead = wait(); + die("Error waiting: $!") if ($dead <= 0); + my $exit = WIFEXITED($?)? WEXITSTATUS($?) : 1; + $first_bad_exit = $exit if ($exit && !$first_bad_exit) +} +exit $first_bad_exit; +EOPERL exit_code=$? [ $exit_code -ne 0 ] && exit_status=$exit_code printf '%s: end at %s\n' "amdump" "`date`" ->>>>>>> upstream:server-src/amdump.sh # Send out a report on the dumps. -$sbindir/amreport$SUF $conf "$@" +$sbindir/amreport $conf --from-amdump "$@" exit_code=$? [ $exit_code -ne 0 ] && exit_status=$exit_code # Roll the log file to its datestamped name. -<<<<<<< HEAD:server-src/amdump.sh.in -$libexecdir/amlogroll$SUF $conf "$@" -======= -$amlibexecdir/amlogroll$SUF $conf "$@" ->>>>>>> upstream:server-src/amdump.sh +$amlibexecdir/amlogroll $conf "$@" exit_code=$? [ $exit_code -ne 0 ] && exit_status=$exit_code # Trim the log file to those for dumps that still exist. -<<<<<<< HEAD:server-src/amdump.sh.in -$libexecdir/amtrmlog$SUF $conf "$@" -======= -$amlibexecdir/amtrmlog$SUF $conf "$@" ->>>>>>> upstream:server-src/amdump.sh +$amlibexecdir/amtrmlog $conf "$@" exit_code=$? [ $exit_code -ne 0 ] && exit_status=$exit_code # Trim the index file to those for dumps that still exist. -<<<<<<< HEAD:server-src/amdump.sh.in -$libexecdir/amtrmidx$SUF $conf "$@" -======= -$amlibexecdir/amtrmidx$SUF $conf "$@" ->>>>>>> upstream:server-src/amdump.sh +$amlibexecdir/amtrmidx $conf "$@" exit_code=$? [ $exit_code -ne 0 ] && exit_status=$exit_code @@ -214,7 +202,6 @@ while [ $days -ge 2 ]; do ndays=`expr $days - 1` mv $errfile.$ndays $errfile.$days exit_code=$? - echo $exit_code [ $exit_code -ne 0 ] && exit_status=$exit_code days=$ndays done