#!/usr/bin/env bash
# systemctl - Termux stub (systemd unavailable)
# Intercepts restart calls and triggers openclaw reload via config.patch (SIGUSR1)

for arg in "$@"; do
    if [ "$arg" = "restart" ]; then
        # Try config.patch reload first (gateway running → SIGUSR1)
        if ! openclaw gateway config.patch \
            "{\"meta\":{\"restartNonce\":\"$(date +%s%N)\"}}" \
            2>/dev/null; then
            # Gateway not running — start it
            openclaw gateway 2>/dev/null || true
        fi
        exit 0
    fi
done

exit 0
