[Bug 1893716] Re: scripts in /etc/update-motd.d/ run even on login via non-interactive scp and sftp sessions

Christian Ehrhardt  1893716 at bugs.launchpad.net
Wed Mar 30 10:07:24 UTC 2022


#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)

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to update-notifier in Ubuntu.
https://bugs.launchpad.net/bugs/1893716

Title:
  scripts in /etc/update-motd.d/ run even on login via non-interactive
  scp and sftp sessions

Status in landscape-client package in Ubuntu:
  In Progress
Status in pam package in Ubuntu:
  Confirmed
Status in ubuntu-release-upgrader package in Ubuntu:
  In Progress
Status in update-motd package in Ubuntu:
  Invalid
Status in update-notifier package in Ubuntu:
  In Progress

Bug description:
  My client has 200+ devices automatically uploading information via
  sftp and scp to a server every few minutes. After a recent update, I
  noticed the load on their server spiking through the roof. Upon
  investigation, I discovered a horde of landscape-sysinfo and
  /usr/bin/lsb_release processes running that correlated with login
  session notifications in /var/log/syslog and the load spikes.

  It appears that even in non-interactive sessions where this
  information will never be seen, the configuration options below in
  /etc/pam.d/sshd cause these items to be launched (in fact, probably
  everything in /etc/update-motd.d). This only started on the system in
  question after a recent set of system updates were installed.

  The content of /etc/update-motd.d/* really, really, really shouldn't
  be executed if the session in question is not interactive, as it
  provides no value at all. Unfortunately, to disable it for these non-
  interactive sessions, we also have to disable it for the interactive
  ones as well where it has some value (though not enough to make
  spiking the load on this server through the roof an acceptable
  tradeoff).

  # Print the message of the day upon successful login.
  # This includes a dynamically generated part from /run/motd.dynamic
  # and a static (admin-editable) part from /etc/motd.
  #session    optional     pam_motd.so  motd=/run/motd.dynamic
  #session    optional     pam_motd.so noupdate

  Also, looking at the script 00-header in /etc/update-motd.d/,
  /usr/bin/lsb_release is being improperly launched, as /etc/lsb_release
  does include the necessary information:

  [ -r /etc/lsb-release ] && . /etc/lsb-release

  if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
          # Fall back to using the very slow lsb_release utility
          DISTRIB_DESCRIPTION=$(lsb_release -s -d)
  fi

  # cat /etc/lsb-release
  DISTRIB_ID=Ubuntu
  DISTRIB_RELEASE=16.04
  DISTRIB_CODENAME=xenial
  DISTRIB_DESCRIPTION="Ubuntu 16.04.7 LTS"

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/landscape-client/+bug/1893716/+subscriptions




More information about the foundations-bugs mailing list