1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#!/bin/sh
#
# Usage: check-auto [seq ...]
#
# Check that if a QA script uses _stop_auto_restart for a
# (systemd) service, it also uses _restore_auto_restart
# (preferably in _cleanup())
#
tmp=/var/tmp/check-auto
trap "rm -f $tmp.*; exit 0" 0 1 2 3 15
verbose=false
if [ X"$1" = X-v ]
then
verbose=true
shift
fi
[ $# -eq 0 ] && set -- `ls -d [0-9]*[0-9] | sort -n`
if [ $# -eq 1 ]
then
grep _stop_auto_restart $1 \
| sed -e "s/^/$1:/"
else
grep _stop_auto_restart $*
fi \
| sed \
-e 's/:/ /' \
-e "/#.*_stop_auto_restart/d" \
| while read seq match
do
svc=`echo "$match" | sed -e 's/_stop_auto_restart //'`
#debug# echo "seq=$seq match=$match svc=$svc"
case "$svc"
in
pmcd|pmlogger|pmie|pmproxy)
;;
*)
echo "$seq: can't handle service \"$svc\" from \"$match\""
;;
esac
rm -f $tmp.cleanup $tmp.remainder $tmp.ok
sed <$seq \
-e '/^[ ]*#.*_restore_auto_restart/d' \
| awk '
/^_cleanup/ { inclean = 1 }
inclean == 1 { print $0 >>"'$tmp.cleanup'" }
inclean == 0 { print $0 >>"'$tmp.remainder'" }
inclean == 1 && $1 == "}" { inclean = 0 }'
if [ -f $tmp.cleanup ]
then
if grep -q "_restore_auto_restart $svc" $tmp.cleanup
then
# good, in _cleanup
$verbose && echo "$seq: _restore_auto_restart $svc in _cleanup()"
touch $tmp.ok
fi
if grep -q '_cleanup_pmda' $tmp.cleanup
then
# special case _restore_auto_restart pmcd done in _cleanup_pmda()
# called from _cleanup()
$verbose && echo "$seq: _restore_auto_restart pmcd in _cleanup_pmda() from _cleanup()"
touch $tmp.ok
fi
fi
if [ ! -f $tmp.ok ]
then
if [ "$svc" = pmcd ]
then
if grep -q '_cleanup_pmda' $seq
then
# special case _restore_auto_restart pmcd done in _cleanup_pmda()
$verbose && echo "$seq: _restore_auto_restart pmcd in _cleanup_pmda()"
touch $tmp.ok
elif grep -E -q '_pmdabcc_cleanup|_pmdaopenmetrics_cleanup|_pmdabpf_cleanup|_pmdaopentelemetry_cleanup|_pmdabpftrace_cleanup' $seq
then
# special case _restore_auto_restart pmcd done in __pmda<foo>_cleanup
$verbose && echo "$seq: _restore_auto_restart pmcd in _pmda<foo>_cleanup()"
touch $tmp.ok
else
[ ! -f $tmp.cleanup ] && echo "$seq: warning: _cleanup() not found"
fi
else
[ ! -f $tmp.cleanup ] && echo "$seq: warning: _cleanup() not found"
fi
fi
if grep -q "_restore_auto_restart $svc" $tmp.remainder
then
echo "$seq: warning: _restore_auto_restart $svc outside _cleanup()"
touch $tmp.ok
fi
[ ! -f $tmp.ok ] && echo "$seq: error: _restore_auto_restart $svc missing"
done
|