Comment 20 for bug 1893716

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

#3 50-landscape-sysinfo

The landscape part already has a statement about "when it is from" as it is not re-executed on high load. This is handy as it will also ensure there is no confusion "from when" this info is if we skip for too frequent invocations.

Since it has an alternate less useful output I've added checks to replace this more often and not replace a good output with a bad one.

--- orig/50-landscape-sysinfo 2022-03-30 07:53:04.320551811 +0000
+++ /etc/update-motd.d/50-landscape-sysinfo 2022-03-30 10:04:00.536053398 +0000
@@ -1,17 +1,39 @@
 #!/bin/sh
-# pam_motd does not carry the environment
-[ -f /etc/default/locale ] && . /etc/default/locale
-export LANG
-cores=$(grep -c ^processor /proc/cpuinfo 2>/dev/null)
-[ "$cores" -eq "0" ] && cores=1
-threshold="${cores:-1}.0"
-if [ $(echo "`cut -f1 -d ' ' /proc/loadavg` < $threshold" | bc) -eq 1 ]; then
- echo
- echo -n " System information as of "
- /bin/date
- echo
- /usr/bin/landscape-sysinfo
-else
- echo
- echo " System information disabled due to load higher than $threshold"
+
+# do try refresh this more than once per minute
+# Due to cpu consumption and login delays (LP: #1893716)
+stamp="/var/lib/landscape/landscape-sysinfo.cache"
+NEED_UPDATE="FALSE"
+find $stamp -newermt 'now-1 minutes' 2> /dev/null | grep -q -m 1 '.' || NEED_UPDATE="TRUE"
+# If the last report in cache wasn't useful (load was too high) still wait at least 5 seconds
+if grep -q "System information disabled" $stamp 2> /dev/null; then
+ find $stamp -newermt 'now-5 seconds' 2> /dev/null | grep -q -m 1 '.' || NEED_UPDATE="TRUE"
 fi
+
+if [ "$NEED_UPDATE" = "TRUE" ]; then
+ # pam_motd does not carry the environment
+ [ -f /etc/default/locale ] && . /etc/default/locale
+ export LANG
+ cores=$(grep -c ^processor /proc/cpuinfo 2>/dev/null)
+ [ "$cores" -eq "0" ] && cores=1
+ threshold="${cores:-1}.0"
+ if [ $(echo "`cut -f1 -d ' ' /proc/loadavg` < $threshold" | bc) -eq 1 ]; then
+ (
+ echo
+ echo -n " System information as of "
+ /bin/date
+ echo
+ /usr/bin/landscape-sysinfo
+ ) > $stamp
+ else
+ # do not replace a formerly good result due to load
+ if ! grep -q "System information as of" $stamp 2> /dev/null; then
+ (
+ echo
+ echo " System information disabled due to load higher than $threshold"
+ ) > $stamp
+ fi
+ fi
+fi
+
+[ ! -r "$stamp" ] || cat "$stamp"

# Info:
It might be worth to note, the optimizations to 95-hwe-eol and 91-release-upgrade save CPU cycles (which is good and worth on its own), but do not improve the delay much.
The optimization to

P.S. I'll need some minor updates for style and avoiding errors (e.g. the && exit 0 was working but could be bad)