#!/bin/bash # Herald Communications Agent wrapper for systemd # Runs on port 18808 export CLAWDBOT_SKIP_USER_SERVICE_CHECK=1 PORT=18808 EXISTING_PID=$(ss -tlnp "sport = :${PORT}" 2>/dev/null | grep -oP 'pid=\K[0-9]+' | head -1) if [ -n "$EXISTING_PID" ]; then EXISTING_PPID=$(ps -o ppid= -p "$EXISTING_PID" 2>/dev/null | tr -d ' ') if [ "$EXISTING_PPID" != "1" ]; then echo "Killing orphaned Herald process PID=$EXISTING_PID (PPID=$EXISTING_PPID)" kill "$EXISTING_PID" 2>/dev/null sleep 2 if kill -0 "$EXISTING_PID" 2>/dev/null; then echo "Force killing PID=$EXISTING_PID" kill -9 "$EXISTING_PID" 2>/dev/null sleep 1 fi else echo "Port $PORT held by systemd-managed PID=$EXISTING_PID — stopping" exit 1 fi fi cd /home/ccuser/herald exec /usr/bin/clawdbot --profile herald gateway run --port $PORT --bind 127.0.0.1 "$@"