From 65f95d815453bb96bc777e37b50efbc16a1c07e3 Mon Sep 17 00:00:00 2001 From: Sven Borkert Date: Thu, 1 Sep 2022 16:27:37 +0200 Subject: [PATCH 1/3] Updated listing of cache contents to include yum and dnf cache every time --- agents/plugins/yum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/plugins/yum b/agents/plugins/yum index 572e23e..7a0af27 100755 --- a/agents/plugins/yum +++ b/agents/plugins/yum @@ -14,7 +14,7 @@ LAST_UPDATE_TIMESTAMP=-1 # get current yum state - use cache directory contents as fingerprint -YUM_CURRENT="$(ls -lR /var/cache/yum/ || ls -lR /var/cache/dnf/)" +YUM_CURRENT="$(ls -lR /var/cache/{yum,dnf}/)" # check if cached listing of /var/cache/yum already exists - create empty one otherwise if [ ! -e $CACHE_YUM_UPDATE ] From 26e93ce29f2e8332fbefc79e0d43fffeadc6651a Mon Sep 17 00:00:00 2001 From: Sven Borkert Date: Thu, 1 Sep 2022 16:38:51 +0200 Subject: [PATCH 2/3] Changed to reboot detection. Will cache last seen uptime and detect reboot when current uptime is lower than the cached uptime --- agents/plugins/yum | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/agents/plugins/yum b/agents/plugins/yum index 7a0af27..83a15f8 100755 --- a/agents/plugins/yum +++ b/agents/plugins/yum @@ -10,6 +10,7 @@ UPDATES=0 SECURITY_UPDATES=0 CACHE_RESULT_CHECK=$MK_VARDIR/cache/yum_result.cache CACHE_YUM_UPDATE=$MK_VARDIR/cache/yum_update.cache +CACHE_PREV_UPTIME=$MK_VARDIR/cache/yum_uptime.cache LAST_UPDATE_TIMESTAMP=-1 @@ -44,8 +45,25 @@ fi # check if system has rebooted - if so, remove cached check file to avoid wrong "reboot required"-state RUNNING_SECS=$(cat /proc/uptime | cut -d" " -f1 | cut -d"." -f1) -# assume 120 seconds for reboot being enough -if (( RUNNING_SECS < 120 )) +# check if cache file with previously seen uptime is existing - create one otherwise +if [ ! -e $CACHE_PREV_UPTIME ] +then + echo 0 > $CACHE_PREV_UPTIME + PREV_UPTIME=0 +elif [ ! -f $CACHE_PREV_UPTIME ] || [ -L $CACHE_PREV_UPTIME ] +then + # something is wrong here... + echo "invalid cache file" + exit 2 +else + # get cached information + PREV_UPTIME=$(cat "$CACHE_PREV_UPTIME") + # save current uptime + echo $RUNNING_SECS > $CACHE_PREV_UPTIME +fi + +# check if current uptime is lower than cached last seen uptime to detect reboot +if (( RUNNING_SECS < PREV_UPTIME )) then # remove pre-reboot cache which requires reboot rm -f $CACHE_RESULT_CHECK From 58d06d5ad9ba4ea76ffcbb80c0a6d0520c10eb3d Mon Sep 17 00:00:00 2001 From: Sven Borkert Date: Thu, 1 Sep 2022 16:41:33 +0200 Subject: [PATCH 3/3] Updated pattern to detect running yum/dnf processes more reliably --- agents/plugins/yum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/plugins/yum b/agents/plugins/yum index 83a15f8..ca143e3 100755 --- a/agents/plugins/yum +++ b/agents/plugins/yum @@ -78,7 +78,7 @@ echo "<<>>" if [ "$YUM_CURRENT" != "$YUM_CACHED" ] || [ ! -s $CACHE_RESULT_CHECK ] then count=0 - while [ -n "$(pgrep -f "python /usr/bin/yum")" ]; do + while [ -n "$(pgrep -f "python (/usr|)/bin/(yum|dnf)")" ]; do if [ $count -eq 3 ]; then echo "Tried to run yum for 30 secs but another yum instance was running" exit 2