Does anyone run a UniFi controller inside an LXC container? I want Home Assistant to be the last to start after my server is fully booted and online.
The first script is what I use:
With that said, is it possible for Home Assistant to be executed the last after all services are started? I want to set a delay for 10 seconds so that presence detection can work properly; otherwise, I get “Not home” for both of my Nexus 6P and Nexus 7 despite both of them being connected to the WiFi network.
I will now do a system restart to see how this works. Thanks.
Update after a couple of minutes later: It seems the OnStartupSec and OnBootSec are the same regardless of whether I set it to 15 or 30 seconds. Changing to lxc.service in the After= directive to see how it goes…
After a couple of minutes later…
Well, I may simply restart Home Assistant manually since the presence detection will simply behave as showing “not home.”
Bit of a late reply but I have a different solution I just came up with today that makes use of oneshot mechanics and simple curl to check if unifi service is available
Create the following /etc/systemd/system/hass-pre.service file (or similar)
[Unit]
Description=Home Assistant helper for UniFi
After=network-online.target unifi.service
Wants=unifi.service
[Service]
Type=oneshot
User=%i
# Enable the following line if you get network-related HA errors during boot
#ExecStartPre=/usr/bin/sleep 60
# Use `whereis hass` to determine the path of hass
ExecStart=/bin/bash -c 'while true; do curl -ksI -m 5 https://0:8443/manage/account/login?redirect=%2Fmanage | grep "200 OK" > /dev/null; if [ $$? == 0 ]; then break; fi; sleep 5; done;'
RemainAfterExit=yes
Then add hass-pre.service to your After= and Wants= inside the main homeassistant systemd file.
Oneshot makes this call block dependent services (hass) until it’s done with the script and RemainAfterExit makes it remain active after the script is done.
So the fake “service” will appear as activating as long as the script is in the loop and will be “activated” when it exits.
Adjust values accordingly. That one-liner simply queries a known URL that responds with “200 OK” header every 5s until it gets the correct response. I’ve tested and it works fine
Let me know!
EDIT: If you’re not running unifi.service in the same environment, you can remove it from Wants= and After= and just rely on curl result
EDIT2: For good measure also add -m 5 to curl parameters so it doesn’t wait too long for each response