I know that to reload a service, there are several methods
/etc/init.d/whatever reload
ubus call service event '{"type":"config.change","data":{"package":"whatever""}}'
reload_config
since reload_config depends on config file md5 values, the same service may reload twice if we run with any of the first two methods, then reload_config.
So what's the proper use case for reload_config? How to prevent from the same service multiple reloading?
I only use it in one specific case: applying the change of a wireguard interface's mtu. With reload_config the ssh connection via the VPN holds, whereas a complete network restart via init.d would break the connection.
I also searched in the source code, there only a few places use reload_config. Interfaces like LuCI use the ubus approach. So, is it correct to assume that reload_config should not be used for a specific service, but rather only when dealing with multiple services where reloading other services is not a concern?
Damned if I know unfortunately . I'll check logread for the different outputs later. Might very well be the case that the "keep ssh connection alive over wg" has a different cause, like keepalive timings or something.
Let me explain in an example. Suppose I changed the settings of ddns in luci gui page, which will then trigger a ubus call to reload the service. Then someone call reload_config, since md5 of config ddns is different, the service was reloaded again.
How to prevent from this? I don't think /etc/init.d/network has a solution for the case.
The md5 should be updated for all those concerned with it. So once the luci save&apply finishes, the md5 (if is even still done this way..??) should be updated. So the next call to reload_config should, use the now updated md5 to compare, and just return ...unless changes were committed between the 2 calls, which does not seem to be the case in which you are describing.
I don't think changes made through the GUI will update the MD5 checksum of a configuration file. For example, changing the hostname in 'Network-Hostnames' causes dnsmasq to reload. However, when checking with /var/run/config.md, the MD5 checksum for DHCP is not updated.
color me curious, its been some time since I have looked into the luci source so I can say what you are saying is incorrect. It could be that the md5's are not being used be all methods ...or at all anymore. the reload_config function is what updates the /var/run/config.md5 file. its generally called after a uci commit... see the uci documentation excerpt below
Showing the not-yet-saved modified values
uci changes
Saving modified values of a single configuration
uci commit configuration_name
reload_config
Saving all modified values
uci commit
reload_config
Luci used to use uci directly, to updated the configs, and somewhere along the line, reload_config was called, when warranted. Perhaps, during the current luci evolution, this functionality has changed, and the md5 is no longer the method to signify conifg changes. I am curious as to how it is done now. Not curious enough to trudge thru the source looking for the answer unfortunately. But, to answer your original question, reload_config is what updates the md5's
I not sure what you are fishing for here, but it seems you've answered your own questions. Unless there is an actual issue, I think its safe to say, the the md5 is no longer used by luci. This is no surprise, this method had allot of moving parts and was ...shall i say scripty. Here is the actual reload_config script, perhaps it will answer any remaining question you may have...