mainsail-crew/sonar

Sonar does not recognize gateway during boot.

fjpanag opened this issue · 4 comments

What happened

I am using MainsailOS on a Raspberry Pi 4, and I enabled sonar.

Right from the start, I had issues with sonar constantly restarting the network.
I have configured target to auto.

It is supposed to ping my gateway in this configuration (192.168.1.1), but it fails to do so.
Manually restarting sonar.service solves the issue, and the correct gateway is properly recognized.

What did you expect to happen

Sonar to properly recognize the gateway, or automatically restart in case of this error.

In any case, proceeding with target being undefined seems wrong.

How to reproduce

Vanilla installation of MainsailOS, with sonar enabled.
Set target to auto and restart the system.

After boot, sonar will try to ping "nothing".

Additional information

Here is sonar's log:

-- Boot 387dbda3bed946d396890161c55c2364 --
Oct 15 17:05:12 voron systemd[1]: Starting Sonar - A WiFi Keepalive daemon...
Oct 15 17:05:12 voron systemd[1]: Started Sonar - A WiFi Keepalive daemon.
Oct 15 17:05:26 voron sudo[600]:     root : PWD=/home/pi/sonar ; USER=pi ; COMMAND=/usr/bin/git describe --always --tags
Oct 15 17:05:26 voron sudo[600]: pam_unix(sudo:session): session opened for user pi(uid=1000) by (uid=0)
Oct 15 17:05:26 voron sudo[600]: pam_unix(sudo:session): session closed for user pi
Oct 15 17:05:27 voron sonar[552]: Sonar - A WiFi Keepalive daemon
Oct 15 17:05:27 voron sonar[552]: Version: v0.1.2
Oct 15 17:05:27 voron sonar[552]: Prepare Startup ...
Oct 15 17:05:27 voron sonar[552]: INFO: Checking Dependencys
Oct 15 17:05:27 voron sonar[552]: Dependency: 'crudini' found in /usr/bin/crudini.
Oct 15 17:05:29 voron sonar[828]: ping: : Name or service not known
Oct 15 17:05:29 voron sonar[552]: Connection lost,  not reachable!
Oct 15 17:05:29 voron sonar[552]: Restarting network in 10 seconds.
Oct 15 17:05:39 voron sonar[1160]: ping: : Name or service not known
Oct 15 17:05:39 voron sonar[552]: Reassociate WiFi connection ...
Oct 15 17:05:39 voron sonar[552]: Restarting dhcpcd service ...
Oct 15 17:05:39 voron sonar[552]: Waiting 10 seconds to re-establish connection ...
Oct 15 17:05:49 voron sonar[1570]: ping: : Name or service not known
Oct 15 17:05:49 voron sonar[552]: Reassociate WiFi connection ...
Oct 15 17:05:49 voron sonar[552]: Restarting dhcpcd service ...
Oct 15 17:05:50 voron sonar[552]: Waiting 10 seconds to re-establish connection ...
Oct 15 17:06:00 voron sonar[1923]: ping: : Name or service not known
Oct 15 17:06:00 voron sonar[552]: Reassociate WiFi connection ...
Oct 15 17:06:00 voron sonar[552]: Restarting dhcpcd service ...
Oct 15 17:06:01 voron sonar[552]: Waiting 10 seconds to re-establish connection ...
Oct 15 17:06:11 voron sonar[552]: WARN: Reconnect failed after 3 retries ...
Oct 15 17:06:11 voron sonar[552]: Attempt paused for 60 seconds.

I have verified that the service file is correct:

#### Sonar - A WiFi Keepalive daemon
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2022
#### https://github.com/mainsail-crew/sonar
####
#### This File is distributed under GPLv3
####

[Unit]
Description=Sonar - A WiFi Keepalive daemon
Documentation=https://github.com/mainsail-crew/sonar
After=udev.service network-online.target nss-lookup.target
Wants=udev.service network-online.target

[Install]
WantedBy=multi-user.target

[Service]
Type=exec
RemainAfterExit=Yes
ExecStart=/usr/local/bin/sonar
Restart=on-failure
RestartSec=5

Assuming that the targets indeed do what their name suggests, sonar should be started after the network is "online".

Sorry, I am busy with updating the OS, so I missed that completly

Your PR looks good to me. Bit unusual way to my eyes, but if it works I dont mind.

Bit unusual way to my eyes, but if it works I dont mind.

I am not terribly familiar with the internals of sonar, so if there is a better way please let me know to update my PR.

No, you dont have to. Only a small syntax issue. I fix that tonight and then push to master :)
Shellcheck requires curly braces for variables otherwise it fails.

The code itself is fine:)

Regards Kwad