#!/bin/sh /etc/rc.common

START=99
STOP=10

USE_PROCD=1

start_service() {
	# Ensure dnsmasq.d directory exists
	mkdir -p /tmp/dnsmasq.d

	# Initial synchronization
	/usr/sbin/network-tweaks-sync sync

	# Set up procd file watcher for vhosts config
	procd_open_instance
	procd_set_param command /bin/sh -c "while true; do sleep 3600; done"
	procd_set_param respawn
	procd_set_param file /etc/config/vhosts /etc/config/network_tweaks
	procd_set_param reload_signal SIGHUP
	procd_close_instance
}

reload_service() {
	# Re-sync when config changes
	/usr/sbin/network-tweaks-sync sync
}

stop_service() {
	# Optionally cleanup on stop (commented out to preserve entries)
	# /usr/sbin/network-tweaks-sync cleanup
	:
}

service_triggers() {
	# Trigger reload when vhosts or network_tweaks config changes
	procd_add_reload_trigger "vhosts" "network_tweaks"
}
