From b9be6491cca4f6b0a01de6a8933b484af509231e Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 17 Oct 2022 18:44:00 +0200 Subject: [PATCH] add diagnose command --- sbin/diagnose | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 sbin/diagnose diff --git a/sbin/diagnose b/sbin/diagnose new file mode 100644 index 0000000..e73b2d1 --- /dev/null +++ b/sbin/diagnose @@ -0,0 +1,52 @@ +#!/bin/bash -e + +MACHINES="" +for nspawn in $(ls /etc/systemd/nspawn/*.nspawn); do + nspawn_file=$(basename $nspawn) + machine=${nspawn_file%.*} + MACHINES="$MACHINES$machine " +done +STARTED="" +DEGRADED="" +found=true +idx=0 +while [ $found = true ]; do + found=false + echo "tentative $idx" + for machine in $MACHINES; do + if ! echo $STARTED | grep -q " $machine "; then + status=$(machinectl -q shell $machine /usr/bin/systemctl is-system-running 2>/dev/null || echo "not started") + if echo "$status" | grep -q degraded; then + STARTED="$STARTED $machine " + DEGRADED="$DEGRADED $machine" + elif echo "$status" | grep -q running; then + STARTED="$STARTED $machine " + else + found=true + echo "status actuel de $machine : $status" + fi + fi + done + sleep 2 + idx=$((idx+1)) + if [ $idx = 60 ]; then + break + fi +done +retcode=0 +for machine in $MACHINES; do + if ! echo "$STARTED" | grep -q " $machine "; then + echo + echo "========= $machine" + machinectl -q shell $machine /usr/bin/systemctl is-system-running 2>/dev/null || echo "not started" + fi +done +echo $DEGRADED +for machine in $DEGRADED; do + echo + echo "========= $machine" + machinectl -q shell $machine /usr/bin/systemctl --state=failed --no-legend --no-pager + retcode=1 +done + +exit $retcode