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>
+# 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
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
}