#!/sbin/openrc-run
# /etc/init.d/hellgate v3 - the hellgated daemon (Gentoo/OpenRC)
# The daemon reads /etc/hellgate.conf itself, auto-attaches when the
# configured NIC exists (or appears later, via rtnetlink), and serves
# hellmon + the `hellgate` CLI on /run/hellgate.sock.

description="THE ROUTER FROM HELL - XDP early-drop gate daemon"

command="/usr/local/sbin/hellgate"
command_args="daemon"
command_background="yes"
pidfile="/run/hellgated.pid"
output_log="/var/log/hellgated.log"
error_log="/var/log/hellgated.log"

depend() {
    # netlink auto-attach means we don't strictly need the NIC yet,
    # but ordering before the firewall keeps the boot sequence tidy
    before nftables bird
    after localmount
}

stop_pre() {
    # daemon exit leaves the gate attached by design; service stop
    # means "protection off", so detach explicitly first
    /usr/local/sbin/hellgate detach >/dev/null 2>&1 || true
}
