X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=blobdiff_plain;f=system-status;h=25a637ee9606788c97e22949b470a811428abf16;hp=78d0fdaec1628894869d7459a6712994352053b8;hb=7e4f3d0a6130b69b7f76a3ff13e510ffbeb1484b;hpb=c926b55471a48cbcd99607ce1e003da55211d166 diff --git a/system-status b/system-status index 78d0fda..25a637e 100755 --- a/system-status +++ b/system-status @@ -6,41 +6,97 @@ if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi -set -eE -o pipefail -trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR - +source /a/bin/errhandle/err status_file=/dev/shm/iank-status shopt -s nullglob shopt -s dotglob +lo() { /usr/local/bin/log-once "$@"; } + write-status() { chars=() glob=(/nocow/btrfs-stale/*) - if [[ -e $glob ]] ; then + if [[ -e ${glob[0]} ]]; then chars+=("STALE!") fi glob=(/m/md/bounces/new/*) - if [[ -e $glob ]]; then + if [[ -e ${glob[0]} ]]; then chars+=("BOUNCE!") + bouncemsg="message in /m/md/bounces/new" fi + lo -1 bounce $bouncemsg glob=(/m/md/alerts/new/* /m/md/alerts/cur/*) - if [[ -e $glob ]]; then + if [[ -e ${glob[0]} ]]; then chars+=("ALERT!") fi if [[ -e /nocow/user/mailtest-failure ]]; then chars+=("MAILPING!") fi + + + 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 + cd /b/ds + 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) + if [[ -s $loglog ]]; then + spamcount=$(stat -c%s $loglog) + else + spamcount=0 + fi + if (( spamcount <= 4 )); then + if grep -q 'spam acl condition' /var/log/exim4/paniclog; then + printf . >>$loglog + fi + /a/bin/distro-setup/epanic-clean + fi + if [[ -s /var/log/exim4/paniclog ]]; then chars+=("PANIC!") + tail -n 20 /var/log/exim4/paniclog | lo -1 paniclog + else + lo -1 paniclog fi source /a/bin/bash_unpublished/source-state - if [[ $MAIL_HOST == $HOSTNAME ]]; then + if [[ $MAIL_HOST == "$HOSTNAME" ]]; then if [[ $(systemctl is-active btrbk.timer) != active ]]; then - chars+=("BTRBK-TIMER!") + chars+=("BTRBK.TIMER!") + bbkmsg="btrbk.timer not enabled" fi + lo -60 btrbk.timer $bbkmsg ## check if last snapshot was within an hour vol=o @@ -56,18 +112,20 @@ write-status() { done if (( maxtime < now - 60*60 )); then chars+=("OLD-SNAPSHOT!") + snapshotmsg="/o snapshot older than 1 hour" fi + lo -1 old-snapshot $snapshotmsg fi cat /a/bin/bash_unpublished/source-state >$status_file - if [[ $chars ]]; then + if [[ ${chars[*]} ]]; then echo "ps_char=\"${chars[*]} \$ps_char\"" >>$status_file fi } write-status -if [[ $@ ]]; then +if [[ $1 ]]; then cat $status_file exit 0 fi