Reloading a service when config changes

I'm developing a luci-app-zerotier module to make it easier to manage zerotier networks on my router. I'm really confused by the fact that when I restart the zerotier service in on_after_commit of my model, it appears that the changes have not actually been committed yet, and zerotier starts with the previous configuration. Is there some other callback I should be using to restart my service?

You should use none of these callbacks. Have your service provide a procd enabled init script with a config reload trigger, then simply operate on the uci file. That should be enough.

I see, so I should really be submitting a change to the zerotier package to update its init script? It looks like the existing one is already procd enabled, but it doesn't explicitly handle reload. Would I need to add a reload that calls restart?

In the meanwhile you can add the following to /etc/config/ucitrack to setup the reload trigger externally until upstream eventually does it itself:

config zerotier
  option init zerotier

(Perform an /etc/init.d/ucitrack restart to make it effective)

You can also ship it as uci-defaults script as part of your luci-app-zerotier package.

In luci-app-zerotier/root/etc/uci-defaults/50_setup_zerotier_reload_trigger (name does not matter but should be unique):

#!/bin/sh

uci -q batch <<-EOF >/dev/null
        delete ucitrack.@zerotier[-1]
        add ucitrack zerotier
        set ucitrack.@zerotier[-1].init=zerotier
        commit ucitrack
EOF

exit 0
1 Like

Thank you for opening that PR, but I think it also needs to restart on reload, without it, zerotier gets confused after a reload

reload_service() {
        stop
        start
}
1 Like

Good catch, I updated the PR accordingly.