Skip to content

Commit

Permalink
apinger-pop for rc.local
Browse files Browse the repository at this point in the history
Dealing with a race condition that comes up when there is NOT a dhcpd
server on the network. This causes the apinger template to never
become populated and thus the wifi radios remain up.

Adding the apinger template to default once to 8.8.8.8 regardless of
being triggered from the dhcp client.

Additionally, there seems to be a second race condition that if the
wireless radio is brought down too early in the startup process it
doesnt actually power down the radios. It leaves them in a weird state
of radios are up, leds are on, but the wifi cli tool thinks there off.
  • Loading branch information
sarcasticadmin committed Jul 30, 2022
1 parent c01db16 commit 5deb893
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions openwrt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ endif
# TODO: should do this automatically for .sh file types
chmod 750 $(TMPL_OUT_DIR)/root/bin/config-version.sh
chmod 750 $(TMPL_OUT_DIR)/root/bin/wifi-details.sh
chmod 750 $(TMPL_OUT_DIR)/root/bin/apinger-pop.sh
chmod 755 $(TMPL_OUT_DIR)/root
chmod 700 $(TMPL_OUT_DIR)/root/.ssh
chmod 640 $(TMPL_OUT_DIR)/root/.ssh/authorized_keys
Expand Down
7 changes: 7 additions & 0 deletions openwrt/files/etc/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
# TODO make this a true service
/root/bin/wifi-details.sh >/dev/null 2>/dev/null </dev/null &

# apinger initial template population
# this needs to remain in the case where DHCP isnt working initially
# there is also a race condition with the wifi interfaces coming online
# and requires a 30 sec grace period before checking via apinger. If not
# the result is wifi is up but the wifi tool detects it as down
(sleep 30 && /root/bin/apinger-pop.sh "8.8.8.8") &> /dev/null &

exit 0
7 changes: 1 addition & 6 deletions openwrt/files/etc/udhcpc.user
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ case "$1" in

# apinger template population
if [ ! -z "$router" ]; then
sed "s/<DEFAULTGATEWAY>/$router/g" /etc/apinger.tmpl > /tmp/apinger.conf
# Only restart apinger if compare has diff
if ! cmp /tmp/apinger.conf /etc/apinger.conf; then
# Cant use "service" since thats a shell function
cp /tmp/apinger.conf /etc/apinger.conf && /etc/init.d/apinger restart
fi
/root/bin/apinger-pop.sh "$router"
fi

if [ ! -z "$hostname" ]; then
Expand Down
14 changes: 14 additions & 0 deletions openwrt/files/root/bin/apinger-pop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

if [ -z ${1} ]; then
echo "[ERROR] require arg for setting the gateway"
exit 1
fi

sed "s/<DEFAULTGATEWAY>/${1}/g" /etc/apinger.tmpl > /tmp/apinger.conf
# Only restart apinger if compare has diff
if ! cmp /tmp/apinger.conf /etc/apinger.conf; then
# Cant use "service" since thats a shell function
sleep 5
cp /tmp/apinger.conf /etc/apinger.conf && /etc/init.d/apinger restart
fi

0 comments on commit 5deb893

Please sign in to comment.