#!/bin/sh /etc/rc.common
# shellcheck shell=dash
# START/STOP/USE_PROCD are consumed by the sourced /etc/rc.common framework.
# shellcheck disable=SC2034
START=99
STOP=10
USE_PROCD=1

start_service() {
	local enabled
	config_load trafficctl
	config_get enabled telegram enabled 0
	[ "$enabled" = "1" ] || return 0

	procd_open_instance telegram
	procd_set_param command /usr/local/bin/trafficctl-telegram.sh
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_set_param respawn 3600 5 5
	procd_set_param file /etc/config/trafficctl
	procd_close_instance
}

service_triggers() {
	procd_add_reload_trigger "trafficctl"
}

reload_service() {
	stop
	start
}
