X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Famcleanup.sh.in;h=f301c5c84ed7bdbf46d151c01db383e60ed19e76;hb=d3b2175e084f88c8736ad7073eacbf4670147aec;hp=5fc55cbfc93618b21d6c10bd1ad89ec33823cbb7;hpb=3ab887b9bc819a846c75dd7f2ee5d41fac22b19f;p=debian%2Famanda diff --git a/server-src/amcleanup.sh.in b/server-src/amcleanup.sh.in index 5fc55cb..f301c5c 100644 --- a/server-src/amcleanup.sh.in +++ b/server-src/amcleanup.sh.in @@ -1,4 +1,4 @@ -#!/bin/sh +#!@SHELL@ # # Amanda, The Advanced Maryland Automatic Network Disk Archiver # Copyright (c) 1991-1998 University of Maryland at College Park @@ -47,47 +47,232 @@ else SUF= fi -if [ $# -ne 1 ] -then - echo "Usage: amcleanup conf" - exit 1 +if test -h /proc/1/exe ; then + if test $# -ge 2 && test "$1" == "-k" ; then + KILL_ENABLE=1 + conf=$2 + shift + shift + elif test $# -ge 1 ; then + KILL_ENABLE=0 + conf=$1 + shift; + else + echo "Usage: amcleanup [-k] conf" + exit 1 + fi +else + if test $# -lt 1 ; then + echo "Usage: amcleanup conf" + exit 1 + else + conf=$1 + shift + KILL_ENABLE=0 + fi fi -conf=$1 -if [ ! -d $confdir/$conf ]; then - echo "amcleanup: could not cd into $confdir/$conf" - exit 1 +if test ! -d $confdir/$conf ; then + echo "amcleanup: could not cd into $confdir/$conf" + exit 1 fi cd $confdir/$conf -logdir=`amgetconf$SUF logdir` -[ $? -ne 0 ] && exit 1 +logdir=`amgetconf$SUF $conf logdir "$@"` +rc=$? +if test $rc -ne 0 ; then + echo "amcleanup: 'amgetconf$SUF logdir' exited with status: $rc" 1>&2 + exit 1 +fi logfile=$logdir/log errfile=$logdir/amdump erramflush=$logdir/amflush -tapecycle=`amgetconf$SUF tapecycle` +tapecycle=`amgetconf$SUF $conf tapecycle "$@"` +rc=$? +if test $rc -ne 0 ; then + echo "amcleanup: 'amgetconf$SUF tapecycle' exited with status: $rc " 1>&2 + exit 1 +fi +dumpuser=`amgetconf$SUF $conf dumpuser "$@"` +rc=$? +if test $rc -ne 0 ; then + echo "amcleanup: 'amgetconf$SUF $conf dumpuser' exited with status: $rc" 1>&2 + exit 1 +fi + +# Check for running processes which should not be +# running right now. +if test ${KILL_ENABLE} -eq 1 ; then + if test -h /proc/1/exe ; then + USER_PROCESS_NAMES="\ + @libexecdir@/amandad \ + @libexecdir@/amcleanupdisk \ + @libexecdir@/amidxtaped \ + @libexecdir@/amindexd \ + @libexecdir@/amlogroll \ + @libexecdir@/amtrmidx \ + @libexecdir@/amtrmlog \ + @libexecdir@/chg-chio \ + @libexecdir@/chg-chs \ + @libexecdir@/chg-disk \ + @libexecdir@/chg-iomega \ + @libexecdir@/chg-juke \ + @libexecdir@/chg-manual \ + @libexecdir@/chg-mcutil \ + @libexecdir@/chg-mtx \ + @libexecdir@/chg-multi \ + @libexecdir@/chg-null \ + @libexecdir@/chg-rait \ + @libexecdir@/chg-rth \ + @libexecdir@/chg-scsi \ + @libexecdir@/chg-zd-mtx \ + @libexecdir@/chunker \ + @libexecdir@/driver \ + @libexecdir@/generic-dumper \ + @libexecdir@/gnutar \ + @libexecdir@/noop \ + @libexecdir@/patch-system \ + @libexecdir@/selfcheck \ + @libexecdir@/sendbackup \ + @libexecdir@/sendsize \ + @libexecdir@/star \ + @libexecdir@/taper \ + @libexecdir@/versionsuffix \ + @sbindir@/amaddclient \ + @sbindir@/amadmin \ + @sbindir@/amaespipe \ + @sbindir@/amcheckdb \ + @sbindir@/amcrypt \ + @sbindir@/amcryptsimple \ + @sbindir@/amdd \ + @sbindir@/amdump \ + @sbindir@/amfetchdump \ + @sbindir@/amflush \ + @sbindir@/amgetconf \ + @sbindir@/amgpgcrypt \ + @sbindir@/amlabel \ + @sbindir@/ammt \ + @sbindir@/amoverview \ + @sbindir@/amplot \ + @sbindir@/amrecover \ + @sbindir@/amreport \ + @sbindir@/amrestore \ + @sbindir@/amrmtape \ + @sbindir@/amserverconfig \ + @sbindir@/amstatus \ + @sbindir@/amtape \ + @sbindir@/amtapetype \ + @sbindir@/amtoc \ + @sbindir@/amverify \ + @sbindir@/amverifyrun" -if [ -f $logfile ]; then - lognotfound=0 + ROOT_PROCESS_NAMES="\ + @libexecdir@/calcsize \ + @libexecdir@/killpgrp \ + @libexecdir@/rundump \ + @libexecdir@/runtar \ + @libexecdir@/dumper \ + @libexecdir@/planner \ + @sbindir@/amcheck" + PREVIOUS_DIR="`pwd`" + cd /proc + PIDS_FOUND=0 + KEEP_CHECKING=1 + while test ${KEEP_CHECKING} -ne 0 ; do + PIDS_THIS_PASS=0 + for search_user in ${dumpuser} root ; do + if test "${search_user}" == "${dumpuser}" ; then + PROCESS_NAMES=${USER_PROCESS_NAMES} + elif test "${search_user}" == "root" ; then + PROCESS_NAMES=${ROOT_PROCESS_NAMES} + fi + for search_pid in [0-9]* ; do + for search_name in ${PROCESS_NAMES} ; do + ls -l /proc/${search_pid}/exe 2>/dev/null | grep ${search_name} >/dev/null + match_name=$? + pid_uid="`cat /proc/${search_pid}/status 2>/dev/null | grep Uid | awk '//{split($_,i); print i[2]}'`" + if test ${match_name} -eq 0 && test "${pid_uid}" == "${search_user}" ; then + echo "amcleanup: Process ${search_name} found running at pid #${search_pid}." + kill_pid=${search_pid} + kill_name=${search_name} + PIDS_FOUND=`expr ${PIDS} + 1` + PIDS_THIS_PASS=1 + break + else + kill_pid="" + continue + fi + done + if test ! -z "${kill_pid}" ; then + if test -d /proc/${kill_pid} ; then + echo "amcleanup: Sending process ${kill_pid} the TERM signal." + kill -15 -- ${kill_pid} + sleep 5 + if test -d /proc/${kill_pid} ; then + echo "amcleanup: Sending process ${kill_pid} the KILL signal." + kill -9 -- ${kill_pid} + fi + sleep 5 + if test -d /proc/${kill_pid} ; then + echo "amcleanup: Process ${kill_pid} did not respond to the KILL signal (and may be hung)!" 1>&2 + KILL_FAILURES=`expr ${KILL_FAILURES} + 1` + fi + else + echo "amcleanup: Process ${kill_pid} no longer running. Skipping..." + fi + fi + done + done + if test ${PIDS_THIS_PASS} -eq 0 ; then + KEEP_CHECKING=0 + else + KEEP_CHECKING=1 + fi + done + if test ${PIDS_FOUND} -gt 0 ; then + echo "amcleanup: ${PIDS_FOUND} Amanda processes were found running." + echo "amcleanup: ${KILL_FAILURES} processes failed to terminate." + else + echo "amcleanup: No Amanda processes were found running." + fi + cd "${PREVIOUS_DIR}" + fi +fi + +retstatus=0 +if test -f $logfile ; then echo "amcleanup: processing outstanding log file." exec /dev/null 2>&1 - amreport$SUF $conf + amreport$SUF $conf "$@" + rc=$? + if test $rc -ne 0 ; then + echo "amcleanup: amreport exited with status: $rc" 1>&2 + retstatus=`expr $retstatus + 1` + fi # Roll the log file to its datestamped name. - amlogroll$SUF $conf + amlogroll$SUF $conf "$@" + rc=$? + if test $rc -ne 0 ; then + echo "acmleanup: amlogroll exited with status: $rc" 1>&2 + retstatus=`expr $retstatus + 2` + fi # Trim the index file to those for dumps that still exist. - amtrmidx$SUF $conf + amtrmidx$SUF $conf "$@" + rc=$? + if test $rc -ne 0 ; then + echo "amcleanup: amtrmidx exited with status: $rc" 1>&2 + retstatus=`expr $retstatus + 4` + fi else echo "amcleanup: no unprocessed logfile to clean up." - - lognotfound=1 fi -if [ -f $errfile ]; then +if test -f $errfile ; then # if log was found, this will have been directed to /dev/null, # which is fine. echo "amcleanup: $errfile exists, renaming it." @@ -98,11 +283,11 @@ if [ -f $errfile ]; then days=1 # First, find out the last existing errfile, # to avoid ``infinite'' loops if tapecycle is infinite - while [ $days -lt $maxdays ] && [ -f $errfile.$days ]; do + while test $days -lt $maxdays && test -f $errfile.$days ; do days=`expr $days + 1` done # Now, renumber the existing log files - while [ $days -ge 2 ]; do + while test $days -ge 2 ; do ndays=`expr $days - 1` mv $errfile.$ndays $errfile.$days days=$ndays @@ -110,7 +295,7 @@ if [ -f $errfile ]; then mv $errfile $errfile.1 fi -if [ -f $erramflush ]; then +if test -f $erramflush ; then # if log was found, this will have been directed to /dev/null, # which is fine. echo "amcleanup: $erramflush exists, renaming it." @@ -121,11 +306,11 @@ if [ -f $erramflush ]; then days=1 # First, find out the last existing erramflush, # to avoid ``infinite'' loops if tapecycle is infinite - while [ $days -lt $maxdays ] && [ -f $erramflush.$days ]; do + while test $days -lt $maxdays && test -f $erramflush.$days ; do days=`expr $days + 1` done # Now, renumber the existing log files - while [ $days -ge 2 ]; do + while test $days -ge 2 ; do ndays=`expr $days - 1` mv $erramflush.$ndays $erramflush.$days days=$ndays @@ -133,6 +318,11 @@ if [ -f $erramflush ]; then mv $erramflush $erramflush.1 fi -$libexecdir/amcleanupdisk $conf +$libexecdir/amcleanupdisk $conf "$@" +rc=$? +if test $rc -ne 0 ; then + echo "amcleanup: amcleanupdisk exited with status: $rc" 1>&2 + retstatus=`expr $retstatus + 8` +fi -exit $lognotfound +exit $retstatus