#!/bin/sh /etc/rc.common
# nDPId Compatibility Layer init script
# Copyright (C) 2025 CyberMind.fr

START=52
STOP=9
USE_PROCD=1

PROG=/usr/bin/ndpid-compat

start_service() {
	local enabled

	config_load ndpid
	config_get_bool enabled compat enabled 1

	[ "$enabled" -eq 0 ] && {
		logger -t ndpid-compat "Compatibility layer disabled"
		return 0
	}

	# Wait for nDPIsrvd
	sleep 2

	procd_open_instance ndpid-compat
	procd_set_param command "$PROG"
	procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_set_param pidfile /var/run/ndpid-compat.pid
	procd_close_instance

	logger -t ndpid-compat "Started compatibility layer"
}

stop_service() {
	logger -t ndpid-compat "Stopping compatibility layer"
}

service_triggers() {
	procd_add_reload_trigger "ndpid"
}
