Hello. I have containers that are working smoothly. I have the following in each container’s config file:
lxc.start.auto = 1
lxc.start.delay = 5
I can’t seem to get
lxc-autostart --list
to show me anything though.
I was thinking of using a service to do shutdown / startup scripts instead. Any advice on best way to shut containers down before reboot and start them back up on restart is greatly appreciated.
I wouldn’t expect the symlink to work because of the way LXC communicates with the monitor process where an exact path match is required, but I was hoping you could convince it to see them with --lxcpath.
That said I haven’t played with lxc-autostart in a long time (well, pretty much since I wrote it ;)).
Okay, so that should let you do lxc-autostart -s -a -P /opt/containers/ to shut them all down. And lxc-autostart -a -P /opt/containers/ to start them all up.
Yeah, you’d want something like our default lxc.service systemd unit which is supposed to be handling this kind of stuff when containers are in the usual location.
Looking at its code, it defaults to auto-starting and auto-stopping containers in the onboot group and uses a default shutdown delay of 5s per container (look at the lxc-containers script).
I don’t know why but when I ran lxc-autostart --list -a -P /opt/containers/ again nothing returned. The container did not start with lxc-autostart -a -P /opt/containers/ but they did shutdown with lxc-autostart -s -a -P /opt/containers/
All the other commands are also going to need the -P /opt/containers/ otherwise LXC will always look in the default path. As you’re running it as an unprivileged user, it will be looking at ~/.local/share/lxc.
I sound dense and I apologize - what exactly should I put in ~/.local/share/lxc? According to your article below, I should put containers there? /var/lib/lxc => ~/.local/share/lxc
I get the feeling that if I point my storage to ‘/home’ set it to btrfs and then do everything default location, lxc-autostart will be able to start / stop the containers automatically?
As you’re running LXC as an unprivileged user, the paths within the user’s home directory will be used indeed and I would expect lxc-autostart and other tools to default to those saving you from having to always pass -P to them.
I think you’ll need to duplicate the systemd unit to run as your lxc user.
Out of the box, the unit that’s shipped with LXC runs as root and looks for containers in /var/lib/lxc as a result.