Question on LXD startup via snapd

I’ve a Python3.8 PyLXD task which is running via systemd and its has a After dependancy on snapd which of course runs lxd.

However I’ve issues in that it runs before the containers themselves have started and I’m getting race conditions.

Is their some way of ascertaining if LXD is running and has started the containers?

I can see there is a volatile.last_state.power configuration entry does that tell me if the container is supposed to be running? So for instance if the container is Stopped and last_state_power says RUNNING is that a good enough sign?

Yeah, that’s a pretty good indication that LXD is still restoring things.
You may also want to make a call to lxd waitready as that will normally block until after the first attempt to bring the containers back up.

I don’t suppose you know how todo the waitready from pyLXD?

There may be a way to get pylxd to hit GET /internal/ready but that’s an internal endpoint so keep in mind that it will only work locally over the unix socket and that it can change at any time (though that particular one hasn’t change in years).