#!/bin/sh /etc/rc.common
# FIPS mesh daemon — procd init script for OpenWrt

USE_PROCD=1
START=95
STOP=10

PROG=/usr/bin/fips
CONFIG=/etc/fips/fips.yaml

start_service() {
	# Ensure TUN module is loaded before starting the daemon.
	modprobe tun 2>/dev/null || true

	procd_open_instance
	procd_set_param command "$PROG" --config "$CONFIG"
	# Respawn: restart after 5 s, give up after 5 consecutive failures within
	# a 3600 s window, then reset the failure counter and try again.
	procd_set_param respawn 3600 5 5
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_close_instance
}

reload_service() {
	restart
}
