constantly firing timers cause systemd to think startup never finishes
[distro-setup] / system-status
index 051de623df85e046d22a01f7d810b2e597f42578..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[@]}")
 
@@ -83,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")
@@ -105,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")
@@ -115,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
 
@@ -213,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
@@ -258,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
@@ -269,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