#!/bin/bash # Cog Operations Support Agent wrapper for systemd # Runs on port 18812 export CLAWDBOT_SKIP_USER_SERVICE_CHECK=1 export CLAWDBOT_STATE_DIR=/root/.clawdbot-cog PORT=18812 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 Cog 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/cog exec /usr/bin/openclaw gateway run --port $PORT --bind loopback "$@"