#!/bin/bash # Radar Scout/AI News Agent wrapper for systemd # Runs on port 18804 export CLAWDBOT_SKIP_USER_SERVICE_CHECK=1 export CLAWDBOT_STATE_DIR=/root/.clawdbot-radar PORT=18804 # Check if something is already holding the port 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 Radar 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/radar exec /usr/bin/openclaw gateway run --port $PORT --bind loopback "$@"