constantly firing timers cause systemd to think startup never finishes
[distro-setup] / system-status
index c3fe13b411d6a8475ae60ec04c43425c727a3024..28c00358255ee79f652587c090e55912a6c8e8df 100644 (file)
@@ -2,8 +2,8 @@
 # Copyright (C) 2019 Ian Kelling
 # SPDX-License-Identifier: AGPL-3.0-or-later
 
-# usage: runs 4 times every 15 seconds unless any args are passed, or we
-# are on battery power, then just runs once.
+# usage: runs once every 15 seconds unless any args are passed, or we
+# then just runs once. On battery power, run once per minute.
 
 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
 
@@ -33,6 +33,11 @@ lo() {
   /usr/local/bin/log-once "$@" | ifne mail -s "$HOSTNAME: system-status $2" root@localhost
 }
 
+loday() {
+  /usr/local/bin/log-once "$@" | ifne mail -s "$HOSTNAME: system-status $2" daylerts@iankelling.org
+}
+
+
 write-status() {
   chars=("${first_chars[@]}")
 
@@ -53,8 +58,24 @@ write-status() {
     fi
   fi
 
+
+  if ip l show tunfsf &>/dev/null; then
+    # this is for tracking dns over tls issue, which
+    # fixvpndns() in brc2 fixes.
+    stat=$(resolvectl dnsovertls tunfsf 2>/dev/null ||: )
+    read _ _ _ istls <<<"$stat"
+    case $istls in
+      no) : ;;
+      *)
+        printf "%s\n" "$istls" | ts >> /tmp/istls.log
+        chars+=("T:$istls")
+        ;;
+    esac
+  fi
+
+
   if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then
-    emacsfiles="$(emacsclient --eval "$(cat /a/bin/ds/unsaved-buffers.el)"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')"
+    emacsfiles="$(emacsclient --eval "$(cat /usr/local/bin/unsaved-buffers.el)"| sed '/^"nil"$/d;s/^"(/E: /;s/)"$//')"
     if [[ $emacsfiles ]]; then
       chars+=("$emacsfiles")
     fi
@@ -67,19 +88,26 @@ write-status() {
   if [[ $(find /var/mail -type f \! -empty -print -quit) ]]; then
     var_mail_msg="message in /var/mail"
   fi
-  lo -1 var_mail $var_mail_msg
+  loday -1 var_mail $var_mail_msg
   glob=(/m/md/bounces/new/*)
   if [[ -e ${glob[0]} ]]; then
     chars+=("BOUNCE")
     bouncemsg="message in /m/md/bounces/new"
   fi
-  lo -1 bounce $bouncemsg
+  loday -1 bounce $bouncemsg
   # emails without the S (seen) flag. this only checks the last flag,
   # but its good enough for me.
   glob=(/m/md/alerts/{new,cur}/!(*,S))
   if [[ -e ${glob[0]} ]]; then
     chars+=("A")
   fi
+
+  glob=(/m/md/daylerts/{new,cur}/!(*,S))
+  if [[ -e ${glob[0]} ]]; then
+    chars+=("L")
+  fi
+
+
   tmp=(/var/local/cron-errors/mailtest-check*)
   if (( ${#tmp[@]} )); then
     chars+=("MAILPING")
@@ -89,8 +117,9 @@ write-status() {
     chars+=("SPAMD")
   fi
 
-  # early in install process, we dont have permission yet for exiqgrep
-  qlen=$(/usr/sbin/exiqgrep -o 600 -c -b | awk '{print $1}') ||:
+  # early in install process, we dont have permission yet for exiqgrep.
+  # 1100 helps allow for system restarts
+  qlen=$(/usr/sbin/exiqgrep -o 1100 -c -b | awk '{print $1}') ||:
   if ((qlen)); then
     qmsg="queue length $qlen"
     chars+=("q $qlen")
@@ -99,7 +128,7 @@ write-status() {
     # No point in emailing about the mailq on a host where we don't
     # check email.
     $MAIL_HOST|bk)
-      lo -120 qlen $qmsg
+      loday -120 qlen $qmsg
       ;;
   esac
 
@@ -151,6 +180,7 @@ write-status() {
         fi
 
         for d in /a/bin/distro-setup /p/c; do
+          [[ -d $d ]] || continue
           cd $d
           if [[ ! -e .git ]]; then
             # some hosts i dont push all of /p/c
@@ -183,6 +213,7 @@ write-status() {
     done
   fi
 
+#  if [[ $(grep -v "exim user lost privilege for using -C option" /var/log/exim4/paniclog 2>/dev/null ||:) ]]; then
   if [[ -s /var/log/exim4/paniclog ]]; then
     chars+=("PANIC!")
     # leave it up to epanic-clean to send email notification
@@ -195,7 +226,7 @@ write-status() {
       chars+=("BTRBK.TIMER")
       bbkmsg="btrbk.timer not enabled"
     fi
-    lo -960 btrbk.timer $bbkmsg
+    lo -48 btrbk.timer $bbkmsg
 
     ## check if last snapshot was within an hour
     vol=o
@@ -240,10 +271,6 @@ write-status() {
 # use this if we want to do something just once per minute
 first_chars=()
 
-power=true
-if [[ -e /sys/class/power_supply/AC/online && $(</sys/class/power_supply/AC/online) == 0 ]]; then
-  power=false
-fi
 
 write-status
 if [[ $1 ]]; then
@@ -251,12 +278,22 @@ if [[ $1 ]]; then
   exit 0
 fi
 
-if ! $power; then
-  exit 0
-fi
+main-loop() {
+while true; do
+  power=true
+  if [[ -e /sys/class/power_supply/AC/online && $(</sys/class/power_supply/AC/online) == 0 ]]; then
+    power=false
+  fi
+  wait=15
+  if ! $power; then
+    wait=60
+  fi
 
-# about 15 minutes
-for ((i=1; i<=60; i++)); do
-  sleep 15
+  sleep $wait
   write-status
 done
+}
+
+# ensure our long operations are one line so we are not prone errors
+# from this file being modified.
+main-loop