Skip to content

Commit

Permalink
Changed to reboot detection. Will cache last seen uptime and detect r…
Browse files Browse the repository at this point in the history
…eboot when current uptime is lower than the cached uptime
  • Loading branch information
sven-borkert committed Sep 1, 2022
1 parent 65f95d8 commit 26e93ce
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions agents/plugins/yum
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 26e93ce

Please sign in to comment.