System Details
OS: Ubuntu Server
Kernel:
5.15.0-173-genericArchitecture: x86_64
Setup: Headless server (accessed via SSH / Tailscale)
Network: WiFi using a USB WiFi adapter (Realtek RTL871X driver)
Problem Summary
I have a home Ubuntu server connected to WiFi using a USB adapter.
When my home router restarts, the server:
Disconnects from WiFi
Attempts recovery via scripts (cron jobs)
Sometimes recovers successfully
But after some time, all cron jobs stop producing logs
SSH connection drops (
connection reset)I need to manually reboot the server to recover
Network Configuration (nmcli)
connection.autoconnect: yes
connection.autoconnect-priority: 10
connection.autoconnect-retries: -1 (default)
connection.autoconnect-slaves: -1 (default)
Cron Jobs
Running as root:
*/2 * * * * /bin/bash /home/madhur/scripts/wifi-recover.sh
*/2 * * * * sleep 20 && /bin/bash /home/madhur/scripts/ping-monitor.sh
*/2 * * * * sleep 40 && /bin/bash /home/madhur/scripts/tailscale-watchdog.sh
Scripts Overview
I have 3 scripts:
wifi-recover.sh
Checks interface state, IP, and ping
If down → runs:
systemctl restart NetworkManagerThen brings interface up and checks connectivity
Restarts
tailscaledafter recovery
ping-monitor.sh
Pings
8.8.8.8If failed → toggles WiFi using:
nmcli radio wifi off/on
tailscale-watchdog.sh
Checks Tailscale health via JSON
Restarts
tailscaledif offline
Observed Logs
WiFi Recover
[12:52:04] Wi-Fi DOWN → Restarting NetworkManager...
[12:52:45] ❌ Recovery FAILED (No IP assigned)
[12:54:01] Wi-Fi DOWN → Restarting NetworkManager...
[12:54:41] ✅ Recovery SUCCESS (IP assigned)
Ping Monitor
[12:52:04] PING FAIL → 100% packet loss
[12:54:01] PING FAIL → Network unreachable
[01:16:03] PING OK
Tailscale
[12:54:01] Online=false → restarting tailscaled
[12:54:09] ✅ restarted
Critical Issue
After the router restart (~12:54 AM):
Recovery appears successful
But:
SSH disconnects (
connection reset)Cron logs stop appearing after that point
Scripts no longer seem to execute
System becomes unreachable until manual reboot
Additional Observations
From journalctl:
NetworkManager is restarted multiple times
WiFi driver logs:
RTL871X: nolinked power savefirmware reloads
Tailscale shows DNS failures:
Temporary failure in name resolution
Questions
Why do cron jobs stop producing logs after network recovery?
- Is cron actually stopping, or are scripts failing silently?
Is restarting
NetworkManagerfrom cron a bad practice?- Could this be causing system instability or race conditions?
Could the USB WiFi adapter (Realtek RTL871X) be causing instability?
- Known issues with power saving / driver resets?
What is the correct way to ensure automatic WiFi reconnection on Ubuntu Server?
Should I:
Avoid
systemctl restart NetworkManager?Use only
nmclicommands?Use a systemd service instead of cron?
How can I make the system:
Recover reliably after router restart
Keep cron/scripts running
Avoid needing manual reboot
Goal
I want a fully autonomous recovery system such that:
If WiFi/router restarts → server reconnects automatically
Tailscale reconnects
SSH remains stable (or recovers)
No manual intervention required