Ok, I'm back with the results of testing your suggestions.
I created the following script /jffs/scripts/service-event-end
Code:
#!/bin/sh
if [ "$1" = "restart" ] && [ "$2" = "wireless" ]
then
logger -p user.info Wireless Service restart, fixing guest networks
brctl delif br0 wl0.1
brctl delif br0 wl1.1
brctl addif br1 wl0.1
brctl addif br1 wl1.1
nvram set lan_ifnames="vlan1 eth1 eth2"
nvram set lan_ifname="br0"
nvram set lan1_ifnames="vlan101 wl0.1 wl1.1"
nvram set lan1_ifname="br1"
nvram commit
killall eapd
eapd
else
logger -p user.info $1 $2
fi
I decided to log all the service-event-end, to see how many times it gets called, and as a confirmation that it's actually better to have a conditional execution.
From the log, here is what I see when I add or remove a guest network:
Code:
May 19 15:37:03 custom_script: Running /jffs/scripts/service-event-end (args: restart wireless)
May 19 15:37:03 admin: Wireless Service restart, fixing guest networks
[…]
May 19 15:37:05 custom_script: Running /jffs/scripts/service-event-end (args: restart qos)
May 19 15:37:05 custom_script: Running /jffs/scripts/service-event-end (args: restart firewall)
May 19 15:37:05 admin: restart firewall
May 19 15:37:05 admin: restart qos
As you can see, the service-event-end script gets called three times, the first one for the wireless restart, the other times for QOS and firewall services.
With your current code, you execute the brctl/nvram/eapd instructions 3 times. Which is not going to do any real harm, but just wastes a bit of time
I would recommend everyone reading this in the future to have a /jffs/scripts/service-event-end as follows
Code:
#!/bin/sh
if [ "$1" = "restart" ] && [ "$2" = "wireless" ]
then
# Optional: log event
# logger -p user.info Wireless Service restart, fixing guest networks
#insert your configuration here for brctl (only the part related to wlx.y, not the one about bringing up a new bridge)
# insert nvram configuration
killall eapd
eapd
fi
As far as I can tell, there is really no reason to have two separate scripts, with the service-event-end calling the other. The code runs fast enough and it's guaranteed not to be blocking to be safe to run from just the service-event-end script. Only if there were code that can block and never exit, then it would be better to spawn a new script, so that in case that portion hangs, the system keeps working. A blocking statement in the service-event-end script would hang the system