Hi all, in the ongoing effort to improve adblock-lean efficiency, I'm looking for a way to selectively stop and start the specific dnsmasq instance which adblock-lean attaches to (in the future we may want to implement support for separate adblocking/parental control for separate instances). Currently adblock-lean simply stops the dnsmasq service (which stops any running instances) when it needs to, and then starts the service when it needs to (which starts all the instances).
I think it should be more efficient to only stop and start the specific instance. Looking at the dnsmasq init service code, I'm noticing functions dnsmasq_start() and dnsmasq_stop(), both of which accept instance ID ($cfg) as an argument and seem to do precisely what's needed (except the latter function doesn't actually kill the running instance? Unless I'm misreading the code). However the init script doesn't provide an API to call these functions?
Am I getting anything wrong here? Any suggestions?
Yeah, I will try that as a last resort. Generally, sourcing another script doesn't have an undo, so doing so permanently merges the code of the sourced script with the code of the sourcing sourcing script in memory, increasing memory use and combining unrelated namespaces, for the duration of the sourcing script's life. This is non-ideal. One could do this in a subshell, then this would only last for the lifetime of the subshell, although still non-ideal.
There is also an issue of relying on internal functions which may change in the future. This is normally solved by having a public API which is guaranteed to be stable (for this case, something like service dnsmasq stop "$instance_id").
And lastly, at this point I'm not sure whether calling these functions will actually do what I want and if there are any landmines to be aware of.
I looked a bit into the init script and it seems to function as you want it on 24.10.0: I can start/stop instances by name, e.g. service dnsmasq start cfg01411c. The service control functions accept instance name as the first argument:
That's a great find! For some reason, I assumed that the start and stop commands don't take arguments, but you are right: they do. Looking back in the version shipped with OpenWrt 22.03, looks like this is supported there as well. I'll test this and post an update here.