Fails if device does not have eth
luigi311 opened this issue · 3 comments
What happened
Fails to run due to /sys/class/net/eth0/operstate not existing on devices that do not have ethernet such as the pi zero 2 w. Looking at the journalctl -u sonar it outputs the following error cat: /sys/class/net/eth0/operstate: No such file or directory
What did you expect to happen
journalctl reports no errors on fresh boot
How to reproduce
enable sonar on raspberry pi zero 2 w
Additional information
Apr 28 09:50:26 mainsail systemd[1]: Starting Sonar - A WiFi Keepalive daemon...
Apr 28 09:50:26 mainsail systemd[1]: Started Sonar - A WiFi Keepalive daemon.
Apr 28 09:50:27 mainsail sonar[614]: Sonar - A WiFi Keepalive daemon
Apr 28 09:50:28 mainsail sonar[633]: Version: v0.0.1
Apr 28 09:50:28 mainsail sonar[638]: Prepare Startup ...
Apr 28 09:50:28 mainsail sonar[643]: INFO: Checking Dependencys
Apr 28 09:50:29 mainsail sonar[660]: Dependency: 'logger' found in /usr/bin/logger.
Apr 28 09:50:29 mainsail sonar[590]: cat: /sys/class/net/eth0/operstate: No such file or directory
worked around this by changing the lib/core.sh check_eth_con function to the following though not sure if you want to go with something else.
if [ -f "/sys/class/net/eth0/operstate" ]; then
if [ "$(cat /sys/class/net/eth0/operstate)" == "up" ]; then
log_msg "WARN: Connected via ethernet, please disable service ..."
log_msg "Stopping sonar.service till next reboot ..."
systemctl stop sonar.service
fi
fi
Hey,
Sorry for my late answer.
Indeed, that is a point that I am totally overlooked. My dev-Pi's are 2 and 4G Models of Pi 4. So, never thougt about the possibilty not to have an ethernet device. Sorry for that.
I will provide a solution for that.
Basicly, I could do it like you mentioned, but I think we could do something shorter :)
Regards