diff --git a/utils/lxc/files/lxc-auto.config b/utils/lxc/files/lxc-auto.config index b5a7ec9920..fa635c91a3 100644 --- a/utils/lxc/files/lxc-auto.config +++ b/utils/lxc/files/lxc-auto.config @@ -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 diff --git a/utils/lxc/files/lxc-auto.init b/utils/lxc/files/lxc-auto.init index 14fe2c509b..bda36bd221 100755 --- a/utils/lxc/files/lxc-auto.init +++ b/utils/lxc/files/lxc-auto.init @@ -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 }