#!/bin/sh /etc/rc.common
# TWAMP Reflector software
# Copyright (C) 2020-2022 IOPSYS Software Solutions AB
# Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>

START=99
STOP=10

USE_PROCD=1
PROG="/usr/sbin/twampd"

start_service() {
	local enable=$(uci -q get twamp.twamp.enable)
	if [ "$enable" = "1" ]; then
		procd_open_instance
		procd_set_param command "$PROG"
		procd_set_param respawn "3" "7" "0"
		procd_close_instance
	fi
}

reload_service() {
        stop
        start
        [ -f /etc/firewall.twamp ] && {
                sh /etc/firewall.twamp
        }
}

service_triggers() {
	procd_add_reload_trigger twamp
}
