#!/usr/bin/env bash # Post-startup Validator Verification # Verifies validator started successfully after ExecStart set -euo pipefail # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' log_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } log_info() { echo -e "${GREEN}[INFO]${NC} $1"; } check_process() { if pgrep -f "besu.*validator" > /dev/null; then log_info "Besu validator process is running" return 0 else log_error "Besu validator process is NOT running" return 1 fi } check_logs() { local error_count=$(journalctl -u besu-validator.service --no-pager -n 20 2>&1 | grep -iE "error|Error|ERROR|exception|Exception|failed|Failed" | wc -l || echo "0") if [ "$error_count" -gt 0 ]; then log_warn "Found $error_count error(s) in recent logs" return 1 else log_info "No errors in recent logs" return 0 fi } main() { log_info "Verifying validator startup..." local issues=0 if ! check_process; then ((issues++)) fi if ! check_logs; then ((issues++)) fi if [ "$issues" -eq 0 ]; then log_info "Validator started successfully" exit 0 else log_error "Validator startup verification failed" exit 1 fi } main "$@"