3 # Amanda, The Advanced Maryland Automatic Network Disk Archiver
4 # Copyright (c) 1991-1998 University of Maryland at College Park
7 # Permission to use, copy, modify, distribute, and sell this software and its
8 # documentation for any purpose is hereby granted without fee, provided that
9 # the above copyright notice appear in all copies and that both that
10 # copyright notice and this permission notice appear in supporting
11 # documentation, and that the name of U.M. not be used in advertising or
12 # publicity pertaining to distribution of the software without specific,
13 # written prior permission. U.M. makes no representations about the
14 # suitability of this software for any purpose. It is provided "as is"
15 # without express or implied warranty.
17 # U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19 # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 # Author: James da Silva, Systems Design and Analysis Group
25 # Computer Science Department
26 # University of Maryland at College Park
30 # amcleanup.sh - clean up and generate a report after a crash.
32 # try to hit all the possibilities here
34 exec_prefix=@exec_prefix@
35 libexecdir=@libexecdir@
40 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb
43 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
44 if test "$USE_VERSION_SUFFIXES" = yes; then
50 if test -h /proc/1/exe ; then
51 if test $# -ge 2 && test "$1" == "-k" ; then
56 elif test $# -ge 1 ; then
61 echo "Usage: amcleanup [-k] conf"
65 if test $# -lt 1 ; then
66 echo "Usage: amcleanup conf"
75 if test ! -d $confdir/$conf ; then
76 echo "amcleanup: could not cd into $confdir/$conf"
82 logdir=`amgetconf$SUF $conf logdir "$@"`
84 if test $rc -ne 0 ; then
85 echo "amcleanup: 'amgetconf$SUF logdir' exited with status: $rc" 1>&2
89 errfile=$logdir/amdump
90 erramflush=$logdir/amflush
91 tapecycle=`amgetconf$SUF $conf tapecycle "$@"`
93 if test $rc -ne 0 ; then
94 echo "amcleanup: 'amgetconf$SUF tapecycle' exited with status: $rc " 1>&2
97 dumpuser=`amgetconf$SUF $conf dumpuser "$@"`
99 if test $rc -ne 0 ; then
100 echo "amcleanup: 'amgetconf$SUF $conf dumpuser' exited with status: $rc" 1>&2
104 # Check for running processes which should not be
106 if test ${KILL_ENABLE} -eq 1 ; then
107 if test -h /proc/1/exe ; then
108 USER_PROCESS_NAMES="\
109 @libexecdir@/amandad \
110 @libexecdir@/amcleanupdisk \
111 @libexecdir@/amidxtaped \
112 @libexecdir@/amindexd \
113 @libexecdir@/amlogroll \
114 @libexecdir@/amtrmidx \
115 @libexecdir@/amtrmlog \
116 @libexecdir@/chg-chio \
117 @libexecdir@/chg-chs \
118 @libexecdir@/chg-disk \
119 @libexecdir@/chg-iomega \
120 @libexecdir@/chg-juke \
121 @libexecdir@/chg-manual \
122 @libexecdir@/chg-mcutil \
123 @libexecdir@/chg-mtx \
124 @libexecdir@/chg-multi \
125 @libexecdir@/chg-null \
126 @libexecdir@/chg-rait \
127 @libexecdir@/chg-rth \
128 @libexecdir@/chg-scsi \
129 @libexecdir@/chg-zd-mtx \
130 @libexecdir@/chunker \
131 @libexecdir@/driver \
132 @libexecdir@/generic-dumper \
133 @libexecdir@/gnutar \
135 @libexecdir@/patch-system \
136 @libexecdir@/selfcheck \
137 @libexecdir@/sendbackup \
138 @libexecdir@/sendsize \
141 @libexecdir@/versionsuffix \
142 @sbindir@/amaddclient \
144 @sbindir@/amaespipe \
145 @sbindir@/amcheckdb \
147 @sbindir@/amcryptsimple \
150 @sbindir@/amfetchdump \
152 @sbindir@/amgetconf \
153 @sbindir@/amgpgcrypt \
156 @sbindir@/amoverview \
158 @sbindir@/amrecover \
160 @sbindir@/amrestore \
162 @sbindir@/amserverconfig \
165 @sbindir@/amtapetype \
168 @sbindir@/amverifyrun"
170 ROOT_PROCESS_NAMES="\
171 @libexecdir@/calcsize \
172 @libexecdir@/killpgrp \
173 @libexecdir@/rundump \
174 @libexecdir@/runtar \
175 @libexecdir@/dumper \
176 @libexecdir@/planner \
183 while test ${KEEP_CHECKING} -ne 0 ; do
185 for search_user in ${dumpuser} root ; do
186 if test "${search_user}" == "${dumpuser}" ; then
187 PROCESS_NAMES=${USER_PROCESS_NAMES}
188 elif test "${search_user}" == "root" ; then
189 PROCESS_NAMES=${ROOT_PROCESS_NAMES}
191 for search_pid in [0-9]* ; do
192 for search_name in ${PROCESS_NAMES} ; do
193 ls -l /proc/${search_pid}/exe 2>/dev/null | grep ${search_name} >/dev/null
195 pid_uid="`cat /proc/${search_pid}/status 2>/dev/null | grep Uid | awk '//{split($_,i); print i[2]}'`"
196 if test ${match_name} -eq 0 && test "${pid_uid}" == "${search_user}" ; then
197 echo "amcleanup: Process ${search_name} found running at pid #${search_pid}."
198 kill_pid=${search_pid}
199 kill_name=${search_name}
200 PIDS_FOUND=`expr ${PIDS} + 1`
208 if test ! -z "${kill_pid}" ; then
209 if test -d /proc/${kill_pid} ; then
210 echo "amcleanup: Sending process ${kill_pid} the TERM signal."
211 kill -15 -- ${kill_pid}
213 if test -d /proc/${kill_pid} ; then
214 echo "amcleanup: Sending process ${kill_pid} the KILL signal."
215 kill -9 -- ${kill_pid}
218 if test -d /proc/${kill_pid} ; then
219 echo "amcleanup: Process ${kill_pid} did not respond to the KILL signal (and may be hung)!" 1>&2
220 KILL_FAILURES=`expr ${KILL_FAILURES} + 1`
223 echo "amcleanup: Process ${kill_pid} no longer running. Skipping..."
228 if test ${PIDS_THIS_PASS} -eq 0 ; then
234 if test ${PIDS_FOUND} -gt 0 ; then
235 echo "amcleanup: ${PIDS_FOUND} Amanda processes were found running."
236 echo "amcleanup: ${KILL_FAILURES} processes failed to terminate."
238 echo "amcleanup: No Amanda processes were found running."
245 if test -f $logfile ; then
246 echo "amcleanup: processing outstanding log file."
247 exec </dev/null >/dev/null 2>&1
248 amreport$SUF $conf "$@"
250 if test $rc -ne 0 ; then
251 echo "amcleanup: amreport exited with status: $rc" 1>&2
252 retstatus=`expr $retstatus + 1`
255 # Roll the log file to its datestamped name.
256 amlogroll$SUF $conf "$@"
258 if test $rc -ne 0 ; then
259 echo "acmleanup: amlogroll exited with status: $rc" 1>&2
260 retstatus=`expr $retstatus + 2`
263 # Trim the index file to those for dumps that still exist.
264 amtrmidx$SUF $conf "$@"
266 if test $rc -ne 0 ; then
267 echo "amcleanup: amtrmidx exited with status: $rc" 1>&2
268 retstatus=`expr $retstatus + 4`
272 echo "amcleanup: no unprocessed logfile to clean up."
275 if test -f $errfile ; then
276 # if log was found, this will have been directed to /dev/null,
278 echo "amcleanup: $errfile exists, renaming it."
280 # Keep debug log through the tapecycle plus a couple days
281 maxdays=`expr $tapecycle + 2`
284 # First, find out the last existing errfile,
285 # to avoid ``infinite'' loops if tapecycle is infinite
286 while test $days -lt $maxdays && test -f $errfile.$days ; do
287 days=`expr $days + 1`
289 # Now, renumber the existing log files
290 while test $days -ge 2 ; do
291 ndays=`expr $days - 1`
292 mv $errfile.$ndays $errfile.$days
295 mv $errfile $errfile.1
298 if test -f $erramflush ; then
299 # if log was found, this will have been directed to /dev/null,
301 echo "amcleanup: $erramflush exists, renaming it."
303 # Keep debug log through the tapecycle plus a couple days
304 maxdays=`expr $tapecycle + 2`
307 # First, find out the last existing erramflush,
308 # to avoid ``infinite'' loops if tapecycle is infinite
309 while test $days -lt $maxdays && test -f $erramflush.$days ; do
310 days=`expr $days + 1`
312 # Now, renumber the existing log files
313 while test $days -ge 2 ; do
314 ndays=`expr $days - 1`
315 mv $erramflush.$ndays $erramflush.$days
318 mv $erramflush $erramflush.1
321 $libexecdir/amcleanupdisk $conf "$@"
323 if test $rc -ne 0 ; then
324 echo "amcleanup: amcleanupdisk exited with status: $rc" 1>&2
325 retstatus=`expr $retstatus + 8`