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 $# -eq 1 ; then
55 elif test $# -eq 2 && test "$1" == "-k" ; then
61 echo "Usage: amcleanup [-k] conf"
65 if test $# -ne 1 ; then
66 echo "Usage: amcleanup conf"
74 if test ! -d $confdir/$conf ; then
75 echo "amcleanup: could not cd into $confdir/$conf"
81 logdir=`amgetconf$SUF $conf logdir "$@"`
83 if test $rc -ne 0 ; then
84 echo "amcleanup: 'amgetconf$SUF logdir' exited with status: $rc" 1>&2
88 errfile=$logdir/amdump
89 erramflush=$logdir/amflush
90 tapecycle=`amgetconf$SUF $conf tapecycle "$@"`
92 if test $rc -ne 0 ; then
93 echo "amcleanup: 'amgetconf$SUF tapecycle' exited with status: $rc " 1>&2
96 dumpuser=`amgetconf$SUF $conf dumpuser "$@"`
98 if test $rc -ne 0 ; then
99 echo "amcleanup: 'amgetconf$SUF $conf dumpuser' exited with status: $rc" 1>&2
103 # Check for running processes which should not be
105 if test ${KILL_ENABLE} -eq 1 ; then
106 if test -h /proc/1/exe ; then
107 USER_PROCESS_NAMES="\
108 @libexecdir@/amandad \
109 @libexecdir@/amcleanupdisk \
110 @libexecdir@/amidxtaped \
111 @libexecdir@/amindexd \
112 @libexecdir@/amlogroll \
113 @libexecdir@/amtrmidx \
114 @libexecdir@/amtrmlog \
115 @libexecdir@/chg-chio \
116 @libexecdir@/chg-chs \
117 @libexecdir@/chg-disk \
118 @libexecdir@/chg-iomega \
119 @libexecdir@/chg-juke \
120 @libexecdir@/chg-manual \
121 @libexecdir@/chg-mcutil \
122 @libexecdir@/chg-mtx \
123 @libexecdir@/chg-multi \
124 @libexecdir@/chg-null \
125 @libexecdir@/chg-rait \
126 @libexecdir@/chg-rth \
127 @libexecdir@/chg-scsi \
128 @libexecdir@/chg-zd-mtx \
129 @libexecdir@/chunker \
130 @libexecdir@/driver \
131 @libexecdir@/generic-dumper \
132 @libexecdir@/gnutar \
134 @libexecdir@/patch-system \
135 @libexecdir@/selfcheck \
136 @libexecdir@/sendbackup \
137 @libexecdir@/sendsize \
140 @libexecdir@/versionsuffix \
141 @sbindir@/amaddclient \
143 @sbindir@/amaespipe \
144 @sbindir@/amcheckdb \
146 @sbindir@/amcryptsimple \
149 @sbindir@/amfetchdump \
151 @sbindir@/amgetconf \
152 @sbindir@/amgpgcrypt \
155 @sbindir@/amoverview \
157 @sbindir@/amrecover \
159 @sbindir@/amrestore \
161 @sbindir@/amserverconfig \
164 @sbindir@/amtapetype \
167 @sbindir@/amverifyrun"
169 ROOT_PROCESS_NAMES="\
170 @libexecdir@/calcsize \
171 @libexecdir@/killpgrp \
172 @libexecdir@/rundump \
173 @libexecdir@/runtar \
174 @libexecdir@/dumper \
175 @libexecdir@/planner \
182 while test ${KEEP_CHECKING} -ne 0 ; do
184 for search_user in ${dumpuser} root ; do
185 if test "${search_user}" == "${dumpuser}" ; then
186 PROCESS_NAMES=${USER_PROCESS_NAMES}
187 elif test "${search_user}" == "root" ; then
188 PROCESS_NAMES=${ROOT_PROCESS_NAMES}
190 for search_pid in [0-9]* ; do
191 for search_name in ${PROCESS_NAMES} ; do
192 ls -l /proc/${search_pid}/exe 2>/dev/null | grep ${search_name} >/dev/null
194 pid_uid="`cat /proc/${search_pid}/status 2>/dev/null | grep Uid | awk '//{split($_,i); print i[2]}'`"
195 if test ${match_name} -eq 0 && test "${pid_uid}" == "${search_user}" ; then
196 echo "amcleanup: Process ${search_name} found running at pid #${search_pid}."
197 kill_pid=${search_pid}
198 kill_name=${search_name}
199 PIDS_FOUND=`expr ${PIDS} + 1`
207 if test ! -z "${kill_pid}" ; then
208 if test -d /proc/${kill_pid} ; then
209 echo "amcleanup: Sending process ${kill_pid} the TERM signal."
210 kill -15 -- ${kill_pid}
212 if test -d /proc/${kill_pid} ; then
213 echo "amcleanup: Sending process ${kill_pid} the KILL signal."
214 kill -9 -- ${kill_pid}
217 if test -d /proc/${kill_pid} ; then
218 echo "amcleanup: Process ${kill_pid} did not respond to the KILL signal (and may be hung)!" 1>&2
219 KILL_FAILURES=`expr ${KILL_FAILURES} + 1`
222 echo "amcleanup: Process ${kill_pid} no longer running. Skipping..."
227 if test ${PIDS_THIS_PASS} -eq 0 ; then
233 if test ${PIDS_FOUND} -gt 0 ; then
234 echo "amcleanup: ${PIDS_FOUND} Amanda processes were found running."
235 echo "amcleanup: ${KILL_FAILURES} processes failed to terminate."
237 echo "amcleanup: No Amanda processes were found running."
244 if test -f $logfile ; then
245 echo "amcleanup: processing outstanding log file."
246 exec </dev/null >/dev/null 2>&1
247 amreport$SUF $conf "$@"
249 if test $rc -ne 0 ; then
250 echo "amcleanup: amreport exited with status: $rc" 1>&2
251 retstatus=`expr $retstatus + 1`
254 # Roll the log file to its datestamped name.
255 amlogroll$SUF $conf "$@"
257 if test $rc -ne 0 ; then
258 echo "acmleanup: amlogroll exited with status: $rc" 1>&2
259 retstatus=`expr $retstatus + 2`
262 # Trim the index file to those for dumps that still exist.
263 amtrmidx$SUF $conf "$@"
265 if test $rc -ne 0 ; then
266 echo "amcleanup: amtrmidx exited with status: $rc" 1>&2
267 retstatus=`expr $retstatus + 4`
271 echo "amcleanup: no unprocessed logfile to clean up."
274 if test -f $errfile ; then
275 # if log was found, this will have been directed to /dev/null,
277 echo "amcleanup: $errfile exists, renaming it."
279 # Keep debug log through the tapecycle plus a couple days
280 maxdays=`expr $tapecycle + 2`
283 # First, find out the last existing errfile,
284 # to avoid ``infinite'' loops if tapecycle is infinite
285 while test $days -lt $maxdays && test -f $errfile.$days ; do
286 days=`expr $days + 1`
288 # Now, renumber the existing log files
289 while test $days -ge 2 ; do
290 ndays=`expr $days - 1`
291 mv $errfile.$ndays $errfile.$days
294 mv $errfile $errfile.1
297 if test -f $erramflush ; then
298 # if log was found, this will have been directed to /dev/null,
300 echo "amcleanup: $erramflush exists, renaming it."
302 # Keep debug log through the tapecycle plus a couple days
303 maxdays=`expr $tapecycle + 2`
306 # First, find out the last existing erramflush,
307 # to avoid ``infinite'' loops if tapecycle is infinite
308 while test $days -lt $maxdays && test -f $erramflush.$days ; do
309 days=`expr $days + 1`
311 # Now, renumber the existing log files
312 while test $days -ge 2 ; do
313 ndays=`expr $days - 1`
314 mv $erramflush.$ndays $erramflush.$days
317 mv $erramflush $erramflush.1
320 $libexecdir/amcleanupdisk $conf "$@"
322 if test $rc -ne 0 ; then
323 echo "amcleanup: amcleanupdisk exited with status: $rc" 1>&2
324 retstatus=`expr $retstatus + 8`