On Mon, 2021-03-01 at 10:54 -0500, Steve Newcomb wrote: > I have 2 hosts that experience interruptions in their > NetworkManager-managed wifi connections. > > In an attempt to force the hosts to restore their wifi connections > more promptly than they otherwise would, I have them running a cron > job called "keepWirelessAlive.py" every 3 minutes. If wifi is > running, the job does nothing. If not, it attempts to restore the > connection using nmcli: > > nmcli device connect wlp3s0
`man nmcli` says about `nmcli device connect`: Connect the device. NetworkManager will try to find a suitable connection that will be activated. It will also consider connections that are not set to auto connect. If no compatible connection exists, a new profile with default settings will be created and activated. This differentiates nmcli connection up ifname "$DEVICE" from nmcli device connect "$DEVICE" The case where nmcli finds a suitable existing profile and connects it is clear. But if the SSID for that profile is not in range, no suitable profile is found and NetworkManager is told to create a new profile. `nmcli device connect` does that by providing an incomplete profile, that NetworkManager completes. However, `nmcli device connect` does not work in that case, because you would at least need to specify the SSID. Thus, creating a profile with `nmcli device connect` does not work. Instead, it would work with `nmcli device connect wifi ssid ...`. It sounds like you don't want to use `nmcli device connect`. Use `nmcli connection up "$PROFILE"` or even `nmcli connection profile "$PROFIILE" ifname "$IFACE"`. If you really don't want to select the profile yourself, and let NetworkManager choose one, maybe you need to first ensure that the Wi- Fi scan list is up to date. That is, issue a `nmcli device wifi rescan` before `nmcli device connect`. But anyway, sometimes connecting to a Wi-Fi may fail. For example, when the SSID cannot be found. It may simply happen sometimes. Ignore the error and retry after a while. If you want to understand why any of that happens, enable level=TRACE log ([1]) in NetworkManager and debug logging for supplicant. [1] https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/contrib/fedora/rpm/NetworkManager.conf#n28 Also, I would try to solve those interruptions, instead of adding a cron job like this... again, the (trace/debug) logfile is the way to go. best, Thomas > > (see below). The command works fine in tests, but when such an attempt > is made automatically by the cron job, it fails, and NetworkManager's > log > messages explain that I've failed to specify a 'wireless' setting (see > below). Alas, I can't find a 'wireless' setting anywhere in > NetworkManager's documentation, so I suspect the log message could be > clearer. > > Everything is OK: > > Mar 1 00:18:01 carp CRON[2615]: (root) CMD > (/usr/local/ch-tools3/keepWirelessAlive.py) > Mar 1 00:21:01 carp CRON[2740]: (root) CMD > (/usr/local/ch-tools3/keepWirelessAlive.py) > > But then the connection is lost: > > Mar 1 00:23:36 carp NetworkManager[657]: <warn> [1614576216.8719] > sup-iface[0x557adf36a8d0,wlp3s0]: connection disconnected (reason -4) > Mar 1 00:23:36 carp NetworkManager[657]: <info> [1614576216.8993] > device (wlp3s0): supplicant interface state: completed -> disconnected > Mar 1 00:23:36 carp NetworkManager[657]: <info> [1614576216.9775] > device (wlp3s0): supplicant interface state: disconnected -> scanning > Mar 1 00:23:40 carp NetworkManager[657]: <info> [1614576220.2651] > device (wlp3s0): supplicant interface state: scanning -> authenticating > Mar 1 00:23:40 carp NetworkManager[657]: <info> [1614576220.3809] > device (wlp3s0): supplicant interface state: authenticating -> > disconnected > Mar 1 00:23:40 carp NetworkManager[657]: <info> [1614576220.8807] > device (wlp3s0): supplicant interface state: disconnected -> scanning > Mar 1 00:23:52 carp NetworkManager[657]: <warn> [1614576232.5545] > device (wlp3s0): link timed out. > Mar 1 00:23:52 carp NetworkManager[657]: <info> [1614576232.5567] > device (wlp3s0): state change: activated -> failed (reason > 'ssid-not-found', sys-iface-state: 'managed') > Mar 1 00:23:52 carp NetworkManager[657]: <info> [1614576232.5667] > manager: NetworkManager state is now DISCONNECTED > Mar 1 00:23:53 carp NetworkManager[657]: <warn> [1614576233.5961] > device (wlp3s0): Activation: failed for connection 'XXXXXXXXX' > Mar 1 00:23:53 carp NetworkManager[657]: <info> [1614576233.5997] > device (wlp3s0): state change: failed -> disconnected (reason 'none', > sys-iface-state: 'managed') > Mar 1 00:23:53 carp dbus-daemon[655]: [system] Activating via systemd: > service name='org.freedesktop.nm_dispatcher' > unit='dbus-org.freedesktop.nm-dispatcher.service' requested by ':1.13' > (uid=0 pid=657 comm="/usr/sbin/NetworkManager --no-daemon ") > Mar 1 00:23:53 carp NetworkManager[657]: <info> [1614576233.6407] > dhcp4 > (wlp3s0): canceled DHCP transaction, DHCP client pid 7824 > Mar 1 00:23:53 carp NetworkManager[657]: <info> [1614576233.6407] > dhcp4 > (wlp3s0): state changed bound -> done > Mar 1 00:23:53 carp NetworkManager[657]: <info> [1614576233.6571] > device (wlp3s0): set-hw-addr: set MAC address to 5E:75:AF:F6:6C:E0 > (scanning) > Mar 1 00:23:54 carp NetworkManager[657]: <info> [1614576234.0453] > dns-mgr: Removing DNS information from /sbin/resolvconf > Mar 1 00:23:54 carp NetworkManager[657]: <info> [1614576234.6754] > device (wlp3s0): supplicant interface state: scanning -> disabled > Mar 1 00:23:54 carp NetworkManager[657]: <info> [1614576234.6755] > device (wlp3s0): supplicant interface state: disabled -> inactive > > So when the keepWirelessAlive.py cron job tries (repeatedly) to bring > the interface back online: > > Mar 1 00:24:01 carp CRON[3023]: (root) CMD > (/usr/local/ch-tools3/keepWirelessAlive.py) > Mar 1 00:24:01 carp NetworkManager[657]: <info> [1614576241.2585] > agent-manager: req[0x557adf45f810, :1.1154236/nmcli-connect/0]: agent > registered > Mar 1 00:24:01 carp NetworkManager[657]: <info> [1614576241.2871] > audit: op="connection-add-activate" pid=3053 uid=0 result="fail" > reason="A 'wireless' setting is required if no AP path was given." > Mar 1 00:24:01 carp /keepWirelessAlive.py: nmcli device connect wlp3s0 > 4 Error: Failed to add/activate new connection: A 'wireless' setting > is > required if no AP path was given. > Mar 1 00:24:04 carp systemd[1]: NetworkManager-dispatcher.service: > Succeeded. > Mar 1 00:27:01 carp CRON[4852]: (root) CMD > (/usr/local/ch-tools3/keepWirelessAlive.py) > Mar 1 00:27:02 carp NetworkManager[657]: <info> [1614576422.0156] > agent-manager: req[0x557adf45f8a0, :1.1154256/nmcli-connect/0]: agent > registered > Mar 1 00:27:02 carp NetworkManager[657]: <info> [1614576422.0184] > audit: op="connection-add-activate" pid=4868 uid=0 result="fail" > reason="A 'wireless' setting is required if no AP path was given." > Mar 1 00:27:02 carp /keepWirelessAlive.py: nmcli device connect wlp3s0 > 4 Error: Failed to add/activate new connection: A 'wireless' setting > is > required if no AP path was given. > Mar 1 00:29:35 carp NetworkManager[657]: <info> [1614576575.6162] > device (wlp3s0): set-hw-addr: set MAC address to 9E:33:C8:6D:BC:33 > (scanning) > Mar 1 00:29:36 carp NetworkManager[657]: <info> [1614576576.0081] > device (wlp3s0): supplicant interface state: inactive -> disabled > Mar 1 00:29:36 carp NetworkManager[657]: <info> [1614576576.0163] > device (wlp3s0): supplicant interface state: disabled -> inactive > Mar 1 00:30:01 carp CRON[5036]: (root) CMD > (/usr/local/ch-tools3/keepWirelessAlive.py) > > ...etc. > > _______________________________________________ > networkmanager-list mailing list > networkmanager-list@gnome.org > https://mail.gnome.org/mailman/listinfo/networkmanager-list
signature.asc
Description: This is a digitally signed message part
_______________________________________________ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list