Skip to content

Commit

Permalink
ffac-ssid-changer: make debug logging configurable
Browse files Browse the repository at this point in the history
Currently, the ffac-ssid-changer is very verbose and causes excessive
logging on devices without a WiFi device (e.g. offloaders).

This change makes the logging configurable via uci and uses logger instead
of stdout for logging.
  • Loading branch information
grische authored and maurerle committed Nov 19, 2023
1 parent 5f98ca2 commit 1d20a39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions ffac-ssid-changer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Adapt and add this block to your `site.conf`:
-- toggeling every minute:
tq_limit_max = 45, -- upper limit, above that the online SSID will be used
tq_limit_min = 35 -- lower limit, below that the offline SSID will be used
debug_log_enabled = true, -- optional: enable extra debug logs
},

# Commandline options
Expand Down
23 changes: 16 additions & 7 deletions ffac-ssid-changer/shsrc/ssid-changer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
#################
# safety checks #
#################
log_debug() {
if [ "${SETTINGS_DEBUG_LOGGING}" = "1" ]; then
logger -t "ffac-ssid-changer" -p debug "$@"
fi
}

safety_exit() {
echo $1, exiting with error code 2
log_debug "$1, exiting with error code 2"
exit 2
}
SETTINGS_DEBUG_LOGGING="$(uci -q get ssid-changer.settings.debug_log_enabled)"
: "${SETTINGS_DEBUG_LOGGING:="0"}"

pgrep -f autoupdater >/dev/null && safety_exit 'autoupdater running'
UT=$(sed 's/\..*//g' /proc/uptime)
[ $UT -gt 60 ] || safety_exit 'less than one minute'
Expand Down Expand Up @@ -101,7 +110,7 @@ if [ $TQ_LIMIT_ENABLED = 1 ]; then
CHECK=0
else
# this is just get a clean run if we are in-between the grace periode
echo "TQ is $GATEWAY_TQ, do nothing"
log_debug "TQ is $GATEWAY_TQ, do nothing"
exit 0
fi
else
Expand All @@ -118,7 +127,7 @@ M=$(($UP % $MINUTES))
HUP_NEEDED=0
if [ "$CHECK" -gt 0 ] || [ "$DISABLED" = '1' ]; then
echo "node is online"
log_debug "node is online"
LOOP=1
# check status for all physical devices
for HOSTAPD in /var/run/hostapd-phy*; do
Expand All @@ -127,7 +136,7 @@ if [ "$CHECK" -gt 0 ] || [ "$DISABLED" = '1' ]; then
LOOP=$((LOOP+1))
CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
if [ "$CURRENT_SSID" = "$ONLINE_SSID" ]; then
echo "SSID $CURRENT_SSID is correct, nothing to do"
log_debug "SSID $CURRENT_SSID is correct, nothing to do"
break
fi
CURRENT_SSID="$(grep "^ssid=$OFFLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
Expand All @@ -154,7 +163,7 @@ if [ "$CHECK" -gt 0 ] || [ "$DISABLED" = '1' ]; then
fi
done
elif [ "$CHECK" -eq 0 ]; then
echo "node is considered offline"
log_debug "node is considered offline"
if [ $UP -lt $FIRST ] || [ $M -eq 0 ]; then
# set SSID offline, only if uptime is less than FIRST or exactly a multiplicative of switch_timeframe
if [ $UP -lt $FIRST ]; then
Expand All @@ -172,7 +181,7 @@ elif [ "$CHECK" -eq 0 ]; then
LOOP=$((LOOP+1))
CURRENT_SSID="$(grep "^ssid=$OFFLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
if [ "$CURRENT_SSID" = "$OFFLINE_SSID" ]; then
echo "SSID $CURRENT_SSID is correct, nothing to do"
log_debug "SSID $CURRENT_SSID is correct, nothing to do"
break
fi
CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
Expand Down Expand Up @@ -211,7 +220,7 @@ if [ $HUP_NEEDED = 1 ]; then
ps|grep hostapd|grep .pid|xargs -n 10 /lib/gluon/eulenfunk-hotfix/check_hostapd.sh
fi
HUP_NEEDED=0
echo "HUP!"
log_debug "Sent HUP to all hostapd to load the new SSID"
fi
if [ $M -eq 0 ]; then
Expand Down

0 comments on commit 1d20a39

Please sign in to comment.