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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#!/bin/sh
# PCP QA Test No. 9000
# If systemd is in the mix, check systemctl status for all PCP
# units.
#
# Copyright (c) 2025 Ken McDonell. All Rights Reserved.
#
if [ $# -eq 0 ]
then
seq=`basename $0`
echo "QA output created by $seq"
else
# use $seq from caller, unless not set
[ -n "$seq" ] || seq=`basename $0`
echo "QA output created by `basename $0` $*"
fi
verbose=false
[ $# -gt 0 -a X"$1" = X--verbose ] && verbose=true
# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check
[ "`$PCP_PS_PROG -p 1 -o comm=`" != systemd ] && _notrun "systemd not active"
[ -d "$PCP_SYSTEMDUNIT_DIR" ] || _notrun "systemd dir $PCP_SYSTEMDUNIT_DIR not found"
_cleanup()
{
cd $here
$sudo rm -rf $tmp $tmp.*
}
status=0 # success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15
_filter()
{
sed \
-e "s@$tmp@TMP@g" \
# end
}
# real QA test starts here
echo "Silence is golden ..."
# pass 1, get ActiveState for every service unit
#
( cd $PCP_SYSTEMDUNIT_DIR; ls -d pcp-*.service pm*.service 2>/dev/null ) \
| while read unit
do
if $sudo systemctl is-active "$unit" >/dev/null 2>&1
then
echo "$unit" >>$tmp.active
else
echo "$unit" >>$tmp.inactive
fi
done
echo "active ..." >>$seq.full
cat $tmp.active >>$seq.full
echo "inactive ..." >>$seq.full
cat $tmp.inactive >>$seq.full
# pass 2, interrogate status of every unit
#
fmt="%-28.28s %-9.9s %-13.13s %-11.11s %-12.12s %-12.12s %-12.12s %-12.12s\n"
$verbose && printf "$fmt" "Unit" "LoadState" "UnitFileState" "ActiveState" "TriggeredBy" "SubState" "ConditionResult"
( cd $PCP_SYSTEMDUNIT_DIR; ls -d pcp-*.service pcp-*.timer pm*.service pm*.timer 2>/dev/null ) \
| while read unit
do
[ -f "$PCP_SYSTEMDUNIT_DIR/$unit" ] || continue
$sudo systemctl status -l --no-pager "$unit" >>$seq_full
systemctl show --no-pager "$unit" >$tmp.tmp
LoadState='missing'
eval `grep ^LoadState= $tmp.tmp`
UnitFileState='missing'
eval `grep ^UnitFileState= $tmp.tmp`
ActiveState='missing'
eval `grep ^ActiveState= $tmp.tmp`
TriggeredBy='missing'
eval `grep ^TriggeredBy= $tmp.tmp`
SubState='missing'
eval `grep ^SubState= $tmp.tmp`
ConditionResult='missing'
eval `grep ^ConditionResult= $tmp.tmp`
$verbose && printf "$fmt" "$unit" "$LoadState" "$UnitFileState" "$ActiveState" "$TriggeredBy" "$SubState" "$ConditionResult"
echo "unit=$unit LoadState=$LoadState UnitFileState=$UnitFileState ActiveState=$ActiveState TriggeredBy=$TriggeredBy SubState=$SubState ConditionResult=$ConditionResult" >>$seq_full
if [ "$LoadState" = loaded -a "$UnitFileState" = disabled ]
then
echo "$unit: loaded but disabled" >>$seq_full
continue
fi
if [ "$LoadState" = loaded -a "$ActiveState" = active ]
then
echo "$unit: loaded and active" >>$seq_full
continue
fi
if [ "$LoadState" = loaded -a "$ActiveState" = inactive -a "$SubState" = dead -a "$TriggeredBy" != missing ]
then
echo "$unit: loaded and waiting for $TriggeredBy" >>$seq_full
continue
fi
if [ "$LoadState" = loaded -a "$ActiveState" = inactive -a "$SubState" = dead -a "$TriggeredBy" = missing ]
then
# .timer units are special, if the associated service was active
# but is now not active, they end up with TriggeredBy = missing
# ditto for the *_daily and *_check services
#
case "$unit"
in
*.timer)
service_unit=`echo "$unit" | sed -e 's/_check//' -e 's/_daily//' -e 's/\.timer/.service/'`
if ! grep -q "^$service_unit\$" $tmp.active
then
echo "$unit: waiting but associated service unit ($service_unit) is not active" >>$seq_full
continue
fi
;;
*_check*|*_daily*)
service_unit=`echo "$unit" | sed -e 's/_check//' -e 's/_daily//' -e 's/_farm//'`
if ! grep -q "^$service_unit\$" $tmp.active
then
echo "$unit: waiting but associated service unit ($service_unit) is not active" >>$seq_full
continue
fi
;;
esac
fi
# pcp-reboot-init.service is a special "one" shot and
# the resulting ActiveState (SubState) can be "inactive (dead)" or
# "active (exited)".
# Ditto for pcp-geolocate.
#
if [ "$unit" = pcp-reboot-init.service -o "$unit" = pcp-geolocate.service ]
then
if [ "$ActiveState+$SubState" = "active+exited" -o \
"$ActiveState+$SubState" = "inactive+dead" ]
then
continue
fi
fi
if [ "$SubState" = dead ]
then
echo "$unit: BAD LoadState=$LoadState UnitFileState=$UnitFileState ActiveState=$ActiveState Substate=dead TriggeredBy=$TriggeredBy"
$sudo systemctl status -l --no-pager "$unit"
continue
fi
echo "$unit: BAD Unclassified LoadState=$LoadState UnitFileState=$UnitFileState ActiveState=$ActiveState TriggeredBy=$TriggeredBy SubState=$SubState"
$sudo systemctl status -l --no-pager "$unit"
done
# success, all done
exit
|