I had the same problem as some others, and hacked away at this solution for some time.
- Typing `stop` & `start` seems to wait for the process to come up in terminal, but not when it's in a bash script apparently.
- Just waiting with `systemctl status NetworkManager` didn't do the trick, so I used ping.
- The redirects (`2>` and `2&1>`) are not to echo the ping/grep outputs to stdout
- put the sleep on 2 seconds, to not spam the chosen server
I was wondering if I should use `www.home-assistant.io` as the ping target. 🤔
A systemd service may be marked as enabled as vendor preset, and this
breaks the check we used to check if it was active.
Here's what you get in an Ubuntu 20.04 installation:
❯ sudo systemctl status ModemManager
● ModemManager.service - Modem Manager
Loaded: loaded (/lib/systemd/system/ModemManager.service; disabled; vendor preset: enabled)
Active: inactive (dead)
❯ systemctl list-unit-files ModemManager.service
UNIT FILE STATE VENDOR PRESET
ModemManager.service disabled enabled
1 unit files listed
While the list-unit-files can be filtered using `--state=enabled`, we
can just rely on `systemctl is-enabled` instead.