How to postpone auto-start of LXC container only after networking is ready?

I have my LXC container configured and running fine. The very last step in my setup was to add it into lxc-auto to make sure it is running after reboot.

Unfortunately this works for my only partially. If I reboot my router the container is up and running however it is not assigned IP address via DHCP and I can see error in log - network initialization failed.

I don’t think there is any problem with a setup of my router as if I connect to the container and run /etc/init.d/network restart everything works fine. I believe the problem is in starting the container before networking on my router is fully up and running.

Please can somebody help me to setup a LXC container to auto-start after reboot in a way to be able to use DHCP? Sure, I can assign static IP address, but I’d prefer to stay with the DHCP option :slight_smile:

I have tried hack described below and it works, but I don’t like it very much.
So, if anybody knows how to fix this in a clean way, please let me know.

I am starting LXC containers with 60 secs (configurable) delay. To prevent too long boot time containers are started in background. Assuming to start multiple container in parallel is not a problem.

Here are my changes

  1. I made copy of lxc-auto under name lxc-dauto (read LXC delayed auto start). Here is the output of diff lxc-auto lxc-dauto
>	local delay_start
> 	config_get delay_start "$cfg" delay_start
< 		/usr/bin/lxc-start -n "$name"
> 		if [ -n "$delay_start" ]; then
> 			( sleep $delay_start ; /usr/bin/lxc-start -n "$name" ) &
> 		else
> 			/usr/bin/lxc-start -n "$name"
> 		fi

2. This is my updated /etc/config/lxc-auto

config container
	option name gitolite
	option delay_start 60
	option timeout 60
1 Like

I think it should be:

lxc.start.delay = 60

in your container config: /srv/lxc/containername/config

1 Like