I do not think so. I believe kmsg will serialize them.
Wrong. Your script is invoked one per each interface in the fire and forget non-blocking mode, so the kernel does not wait until scripts finish and keep on setting up interfaces. So, yes the script is absolutely running many instances.
There are multiple problems here: the firewall gets reloaded several times during the network setup, so without proper planning and synchronization the approach will not work reliably.
Right, and let's now image each line is a script invocation in a very quick succession. I worked through a similar use case and stabilizing this kind of functionality is no easy task.
I did a couple reboots and it executed every time the hotplug scripts.
(I understand now they got executed all the time before, but the simultanious calls caused the problems)
I actually want to do a NETMAP to the IP address on the lan interface. Means I have to do it every time when the IP address changes there, or if an IP address comes up for the first time after a reboot.
Is there any better solution as to do this via a hotplug script in /etc/hotplug.d/net/99-netmap?
That is the best way I know. The problem is you have to wait for all the network changes to complete and the firewall restarts to stop, before you script actually does anything. It is challenging, because there are many concurrent invocations and only one can proceed while all the others need to finish without doing anything.
I suggest you use the flock approach and once the lock is obtained, you can create a file in /tmp/ if it does not exist. If the file exists, then the script exits without doing anything.
The lucky script can then wait for a minute or so (test this) and make all the config changes AND delete the file created in /tmp/, so that the next network reconfiguration could apply your changes again.
It happens not very often (maybe ever 10-20 times of rebooting) that the script gets not executed during the boot, but if it happens, then it also gets not executed on the shutdown.
I was able to take a sceenshot on the shutdown after the script did not work during the boot.
If I have the system running after the script got not executed during the boot and I restart the network, then the script gets executed and then also later on the shutdown.
Is there anything else what I could check if I have the system running after a boot which did not execute the scripts?
Independent from that, that there is be a better solution to do my netmap, why is this iface event not called reliably?
Hotplug scripts which get not executed during the boot could cause other problems as well.
For example gets the firewall script also not called in this situation.
root@test-r1:~# logread | grep "Reloading firewall"
No log entry for the firewall (created by /etc/hotplug.d/iface/20-firewall) if this happens with the not-executed scripts during boot.
root@test-r1:~# /etc/init.d/network restart
root@test-r1:~# logread | grep "Reloading firewall"
Sun Jun 21 12:48:45 2020 user.notice firewall: Reloading firewall due to ifup of lan (br-lan)
root@test-r1:~# reboot
root@test-r1:~# logread | grep "Reloading firewall"
Sun Jun 21 12:49:22 2020 user.notice firewall: Reloading firewall due to ifup of lan (br-lan)
After another reboot, on which it did execute my script, the firewall entry was created in the log.
(I suppressed for testing all the executions of iptables commands in my script)
I think it is not solved, since the iface script gets not executed on every boot.
you have return to this hypothesis already before... and twice you been convinced that it was flawed. i'm not saying that you are wrong. but unless you provide "definitive evidence" that substantiates this theory... and explain in detail why such a theory is true... at this stage in the game I think you have to trust the advice you've been given and know that it IS run EVERY time on BOOT. and invest some time writing detailed scripts to prove or disprove other possible influences and advice before immediately oversimplifying things again. or even better... diversify your efforts so as not to let one "method" stop you from achieving your end result.
unticked... please remember to mark one when you feel you have found the answer you are looking for.
Add this line before the the first echo command, reboot, and see if there is anything in that file.
exec >>/tmp/exec.log 2>&1
Also, remove kmsg and use /tmp/if_dbg to monitor the script.
UPDATE: I do not know the sequence of things, but it is possible that kmsg is not always fully setup yet by the time the hot plug scripts are executed, so using a file is a more reliable solution.
Installed a new and clean OpenWRT instance in VMware.
Only changed its static lan IP address to DHCP.
Created a test script /root/test.sh
#!/bin/sh
sleep 30
if logread | grep -F "Reloading firewall"; then
reboot
fi
Added a call for this script to /etc/rc.local.
This script issues a reboot after 30s if there is "Reloading firewall" firewall detected in the log, which gets created by the /etc/hotplug.d/iface/20-firewall script which came with OpenWRT.
This was running for more than an hour and it never stopped rebooting.
Means there was no problem running the hotplug scrips.
Then I installed these modules, but changed nothing else. Same modules are installed on the other instance which causes the problems. base-files busybox comgt-ncm dnsmasq dropbear e2fsprogs flock htop ip6tables iptables-mod-dnetmap iptables-mod-nat-extra kernel kmod-3c59x kmod-8139too kmod-bnx2 kmod-button-hotplug kmod-e100 kmod-e1000 kmod-e1000e kmod-igb kmod-ipt-offload kmod-natsemi kmod-ne2k-pci kmod-nf-nathelper-extra kmod-pcnet32 kmod-r8169 kmod-sis900 kmod-tg3 kmod-usb-net-rndis kmod-via-rhine kmod-via-velocity logd luci-app-wol luci-proto-3g luci-ssl miniupnpc mkf2fs mtd natpmpc ntpclient odhcp6c odhcpd-ipv6only openvpn-openssl partx-utils picocom ppp ppp-mod-pppoe ppp-mod-pptp px5g-mbedtls uci urandom-seed urngd usb-modeswitch usbutils
I did not change anything in the configuration, but after the installation of these modules my test script stopped after a couple reboots.
Means to me that probably one of these packages causes a problem to the execution of the iface hotplug script.
The reason messages could be missing is because the logger might not be fully operational yet. The more packages you install, the more work the router has to do on startup, the higher probability that the logger starts later sometimes.
The best approach is to use flock and write in your own file: the file system is definitely up and operational when the scripts are invoked.