X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=system-status;h=e137d06f3b4b15c44b884e6dc04e8eb17d0a3759;hb=41235a1a070914920dc84f352abee00deccda146;hp=c6f3fe7f5144d3c3661196289cc8cfbb062059ed;hpb=6f1f8a104c9b38936ade2d27e835479523985133;p=distro-setup diff --git a/system-status b/system-status index c6f3fe7..e137d06 100755 --- a/system-status +++ b/system-status @@ -2,7 +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, then just runs once +# usage: runs 4 times every 15 seconds unless any args are passed, or we +# are on battery power, then just runs once. if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi @@ -15,7 +16,7 @@ shopt -s dotglob lo() { /usr/local/bin/log-once "$@"; } write-status() { - chars=() + chars=("${first_chars[@]}") glob=(/nocow/btrfs-stale/*) if [[ -e ${glob[0]} ]]; then @@ -35,6 +36,43 @@ write-status() { chars+=("MAILPING!") fi + qlen=$(/usr/sbin/exiqgrep -o 60 -c -b | awk '{print $1}') + if ((qlen)); then + chars+=("q $qlen") + fi + + cd /b/ds + if ! make -q ~/.local/distro-begin || [[ $(<~/.local/distro-begin) != 0 ]]; then + chars+=("DISTRO-BEGIN!") + fi + + if ! make -q ~/.local/distro-end || [[ $(<~/.local/distro-end) != 0 ]]; then + chars+=("DISTRO-END!") + fi + + f=~/.local/conflink + if [[ -e $f ]]; then + now=$(date +%s) + fsec=$(stat -c%Y $f) + fmin=$(( (fsec - now ) / 60 + 1 )) + fminplus=$(( fmin + 60*24 )) + # Filesystem files get copied, so find any newer than the last run. + # The rest are hueristics: + # Given the last time we added a file in git, is that newer than the last conflink run. + # Given new files not added to git, were they modified more recently than the last conflink? but, + # push their modification time back by a day so we can develop them before needing to add them to git. + if (( $(date -d "$(git log --diff-filter=ACR --format=%aD -1)" +%s) > fsec )) || \ + [[ $(find {/a/bin/ds,/p/c}{/filesystem,/machine_specific/$HOSTNAME/filesystem} -mmin $fmin -type f -print -quit 2>/dev/null) ]] \ + || [[ $(find $(git ls-files -o --exclude-standard) -mmin $fminplus -type f -print -quit) ]]; then + chars+=("CONFLINK!") + fi + fi + + if [[ ! -e $f || $(<$f) != 0 ]]; then + chars+=("CONFLINK!") + fi + + ## Clean the paniclog, but only up to 4 times per day, or else we ## should investigate. loglog=/tmp/panicloglog-$(date --rfc-3339=date) @@ -44,7 +82,7 @@ write-status() { spamcount=0 fi if (( spamcount <= 4 )); then - if grep -q 'spam acl condition' /var/log/exim4/paniclog; then + if grep -q 'spam acl condition' /var/log/exim4/paniclog &>/dev/null; then printf . >>$loglog fi /a/bin/distro-setup/epanic-clean @@ -59,6 +97,7 @@ write-status() { source /a/bin/bash_unpublished/source-state if [[ $MAIL_HOST == "$HOSTNAME" ]]; then + bbkmsg= if [[ $(systemctl is-active btrbk.timer) != active ]]; then chars+=("BTRBK.TIMER!") bbkmsg="btrbk.timer not enabled" @@ -67,7 +106,13 @@ write-status() { ## check if last snapshot was within an hour vol=o - snaps=(/mnt/root/btrbk/$vol.20*) + # this section generally copied from btrbk scripts, but + # this part modified to speed things up by about half a second. + # I'm not sure if its quite as reliable, but it looks pretty safe. + # Profiled it using time and also adding to the top of the file: + # set -x + # PS4='+ $(date "+%2N") ' + snaps=($(ls -1avdr /mnt/root/btrbk/$vol.20*|head -n1)) now=$(date +%s) maxtime=0 for s in ${snaps[@]}; do @@ -91,11 +136,23 @@ write-status() { fi } +# use this if we want to do something just once per minute +first_chars=() + +power=true +if [[ -e /sys/class/power_supply/AC/online && $(