#!/bin/bash
# Check service status on a VMID
# Usage: ./scripts/check-service.sh <VMID> <VMIP>

set -e

VMID="${1:-}"
VMIP="${2:-}"

if [ -z "$VMID" ] || [ -z "$VMIP" ]; then
  echo "Usage: $0 <VMID> <VMIP>"
  echo "Example: $0 2400 192.168.11.240"
  exit 1
fi

echo "Checking RPC Translator service on VMID $VMID ($VMIP)..."
echo ""

# Check if service is running
echo "Service status:"
ssh "root@$VMIP" "systemctl status rpc-translator-138.service --no-pager -l" || true

echo ""
echo "Recent logs:"
ssh "root@$VMIP" "journalctl -u rpc-translator-138.service -n 20 --no-pager" || true

echo ""
echo "Health check:"
curl -s "http://$VMIP:9545/health" | jq '.' || echo "Health check failed"
echo ""
