How to trigger init script from luci

I have added a global vlans (not switch vlans) page to luci intended to set vlans on the ethernet, wireless and localhost interfaces. The page interfaces ok with the uci /etc/config/vlans file. Now I need to have the luci save&apply trigger a function in the /etc/init.d/vlans file which will use ip commends to actually set the vlans on the interfaces. I think I've read that my init.d file needs to have a

  • service_triggers function containing the line
  • procd_add_reload_trigger "vlans"
  • a function, not sure of the name, which does the ip commands
    Nothing seems to happen when the luci save&apply button is clicked, though.

The init script is loaded when
config vlans
option init vlans
is added to ucitrack.

I didn't find a single question mark in your post ... :wink: ... probably you're looking for "Save & Apply" hooks, see here.

For example use cases scan the luci github repo.

Try this:
save to /etc/init.d/mydaemon

#!/bin/sh /etc/rc.common
# Bottle startup script
# start it after everything else is loaded
START=98
start() {
    logger start something
    /root/run_script.sh
}
stop() {
        killall /root/run_script.sh
        logger stopped something
}

then

chmod 755 /etc/init.d/mydaemon

/etc/init.d/mydaemon restart
/etc/init.d/mydaemon enable

you should able to see "mydaemon" on system->startup http://192.168.1.1/cgi-bin/luci/admin/system/startup

Thanks. I do have a script /etc/init.d/vlans. The trouble I was having was in getting this script triggered when the Save&Apply button was pressed. I eventually went for an old-fashioned

m = Map("vlans", translate("VLANs"), translate(""))_
function m.on_commit(map)_
m.description = "on_commit"_
luci.sys.call("/etc/init.d/network restart")_
end

from the luci map, which does invoke a network restart.
Now the challenge is to navigate the restart process to integrate the vlan setup from the /etc/config/vlans uci file.
Having trouble there, though, so I'll go back to my init script and see if i can tweak the running network

Hi @enjay77
I'm looking for like you, "getting this script triggered when the Save&Apply button was pressed".I want to start or stop a script based on a value or a checkbox on my Luci page .
If you have something which can help me
Thanks

I only have my script triggered when the Save&Apply button is pressed.
Sorry, I don't know how to start or stop a script based on a value or a checkbox.