xiaowei-system/scripts/wal-sentinel.sh

24 lines
870 B
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# WAL 哨兵:抓谁动了 state.db-wal
LOG=~/.hermes/wal-watch.log
while true; do
PIDS=$(systemctl --user show hermes-gateway -p MainPID --value)
if [ -n "$PIDS" ] && [ "$PIDS" != "0" ]; then
DEL=$(ls -l /proc/$PIDS/fd 2>/dev/null | grep -c 'state.db-wal (deleted)')
if [ "$DEL" -gt 0 ] && [ ! -f /tmp/wal_alert_sent ]; then
{
echo "==== $(date '+%F %T') WAL-DELETED detected, gateway PID=$PIDS"
ps aux --sort=-%cpu | head -15
grep -l . /proc/[0-9]*/cmdline 2>/dev/null | while read f; do
c=$(tr '' ' ' < "$f" 2>/dev/null)
case "$c" in *wal*|*state.db*|*stabilize*|*recover*) echo "SUSPECT $(dirname $f | tr -dc 0-9): $c";; esac
done
last=$(w -h 2>/dev/null; who)
echo "logged-in: $last"
} >> $LOG 2>&1
touch /tmp/wal_alert_sent
fi
fi
sleep 20
done