lxc-auto: add optional dnsmasq dep wait on startup

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>
This commit is contained in:
John Audia
2026-02-06 16:41:44 -05:00
committed by Hannu Nyman
parent 7c3e376967
commit eccee9a590
2 changed files with 32 additions and 0 deletions

View 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

View File

@@ -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
}