lxc-auto: add optional dnsmasq dep wait on startup
authorJohn Audia <therealgraysky@proton.me>
Fri, 6 Feb 2026 21:41:44 +0000 (16:41 -0500)
committerHannu Nyman <hannu.nyman@iki.fi>
Sat, 21 Feb 2026 15:51:20 +0000 (17:51 +0200)
Add opt-in support for waiting for dnsmasq to be fully initialized
before starting LXC containers. This addresses issues where containers
that depend on DNS resolution (e.g., AdGuardHome) start before dnsmasq
has loaded its DHCP lease table, resulting in hostnames not being
resolved to IP addresses.

The feature is controlled by two new optional UCI config options in
/etc/config/lxc-auto whose usage is commented therein.

No new depends are introduced with this change.

Signed-off-by: John Audia <therealgraysky@proton.me>
utils/lxc/files/lxc-auto.config
utils/lxc/files/lxc-auto.init

index b5a7ec992011b77d7a5975ae291c1dc38489a0f6..fa635c91a3be8240aad55b4c6d42fea2377d3d7c 100644 (file)
@@ -1,3 +1,9 @@
+# Global configuration (optional)
+# Uncomment to enable waiting for dnsmasq before starting containers
+#config global 'global'
+#      option wait_dnsmasq '1'
+#      option dnsmasq_timeout '30'
+
 #config container
        #option name container1
        #option timeout 300
index 14fe2c509b87bb2918f347208c01f1289457d0cb..bda36bd221f4064424aaa98ca5ec21eaa321f244 100755 (executable)
@@ -43,6 +43,32 @@ stop_container() {
 
 start() {
        config_load lxc-auto
+       
+       local wait_dnsmasq
+       local dnsmasq_timeout
+       config_get_bool wait_dnsmasq global wait_dnsmasq 0
+       config_get dnsmasq_timeout global dnsmasq_timeout 30
+       
+       if [ "$wait_dnsmasq" -eq 1 ]; then
+               local count=0
+
+               while [ $count -lt $dnsmasq_timeout ]; do
+                       local dnsmasq_running=$(ubus call service list '{"name":"dnsmasq"}' 2>/dev/null | jsonfilter -e '@.dnsmasq.instances.*.running')
+
+                       if [ "$dnsmasq_running" = "true" ]; then
+                               logger -t lxc-auto "dnsmasq service confirmed running via procd"
+                               break
+                       fi
+
+                       sleep 1
+                       count=$((count + 1))
+               done
+
+               if [ $count -ge $dnsmasq_timeout ]; then
+                       logger -t lxc-auto "WARNING: dnsmasq not running after ${dnsmasq_timeout}s, starting containers anyway"
+               fi
+       fi
+       config_load lxc-auto
        config_foreach start_container container
 }