OpenWrt Forum Archive

Topic: Restarting service from LuCI-based GUI

The content of this topic has been archived on 6 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I'm working on LuCI interface for my portproxy tool. I'm keeping the whole configuration in /etc/config/softwire. I've developed LuCI module that allows easy edition of that file.
Edition and saving works ok. The only thing I can't find is how to restart service after user click "save&apply.". As I understand, LuCI will then call uci commit.

But how do I force uci (or LuCI) to execute something like "/etc/init.d/portproxy restart"?
There' s a good example of what I'am trying to accomplish: port forwarding configuration. Once you modify something and commit the changes, LuCI web is reloaed and  "Applying changes" table appears with information regarding firewall and qos restarting. I believe something like:
/etc/init.d/firefwall restart
/etc/init.d/qos restart

But how do I make my package to restart once I commit changes to my own configuration?

Any tips and pointers to the already existing solutions are more than welcome.

Tomek

Hi, take a look at /etc/config/ucitrack, this files specifies which services are related to which config files.

~ JoW

jow wrote:

Hi, take a look at /etc/config/ucitrack, this files specifies which services are related to which config files.

Thanks for the tip. I've added following section to ucitrack:

config 'softwire'
    option 'init' 'portproxy'
    list 'affects' 'portproxy'

but it didn't help. I'm not sure if the list line is required or not, so I've tried both with and without it. When use my LuCI page to update relevant section in my /etc/config/softwire config file, my service is not restarted.

Here are some extra information that may be helpful:
My config file is named softwire (it is located in /etc/config/softwire) and my service script is located at /etc/init.d/portproxy. First, I've added this section manually (using vi), which I think is not the 'proper' approach, as I should use uci to do that. To make sure that uci recognizes the changes, I've exported ucitrack file and imported it back. Right now 'uci show ucitrack' displays my changes correctly.

I'm not sure if that is relevant, but in Makefile for my portproxy package, I have this clause:

define Package/portproxy/install
...
        $(INSTALL_DIR) $(1)/etc/config 
        $(INSTALL_DATA) ./files/config/softwire $(1)/etc/config/softwire
...
endef

define Package/$(PKG_NAME)/conffiles
/etc/config/softwire
endef

so I think my config file is properly installed and marked as config.

I don't know much about uci, so to make sure that there are no caching ivolved, I've also restarted my router. Still, it doesn't work. Making changes to my softwire config doesn't restart my portproxy service. sad

Do you have an init script named "portproxy" ?

Ok, I've solved this. I wish this whole UCI+LuCI operation was described in some docs somewhere... Anyway, here are some extra info in case someone else hits the same problem.

Configuration parameters are expected to be stored in /etc/config/name-of-your-config, in my case it was /etc/config/softwire. Service scripts are located in the usual location /etc/init.d, in my case it was /etc/init.d/portproxy. I also had to add several lines to /etc/config/ucitrack to indicate that /etc/config/softwire config file is associated with portproxy service (/etc/init.d/portproxy file).

Now, when LuCI webpage commits UCI changes, i.e. when you hit Save&Apply or Apply button, several things happen. Among others, also Cursor.apply() method from luci/model/uci.lua file is called. As  a result, external script /sbin/luci-reload is invoked. You can take a closer look, if necessary. In my case the problem was that portproxy service was disabled. It was running (started manually), so I thought it will do the trick. Enabling the service (/etc/init.d/portproxy enable) solved the problem.

Now it works. JoW, thanks again for your help.

Sorry for dig this old post out.

What I wonder know is a way to restart a service for all config changes. No matter which config it is, once a config is changed, and be saved and applied, my services would restart.
It seems that to add several same lines in the ucitrack is possible.
But does ucitrack have support for all config? Or I have to add something in LuCI's "save & apply" button?

The discussion might have continued from here.