#!/usr/bin/env bash
# process_check.sh — systemd service liveness.
set -euo pipefail

SERVICE="${1:-}"
if [ -z "$SERVICE" ]; then
  echo '{"health":"unknown","signalKind":"process-check","evidence":"no service name provided"}'
  exit 0
fi

if ! command -v systemctl >/dev/null 2>&1; then
  echo '{"health":"unknown","signalKind":"process-check","evidence":"systemctl not found"}'
  exit 0
fi

STATE=$(systemctl is-active "$SERVICE" 2>/dev/null || echo "unknown")

if [ "$STATE" = "active" ]; then
  echo "{\"health\":\"healthy\"}"
else
  echo "{\"health\":\"degraded\",\"signalKind\":\"$SERVICE\",\"evidence\":\"$SERVICE is $STATE\"}"
fi
