pub fn ensure_running(
engine: &Engine,
plan: &ContainerPlan,
user: HostUser,
) -> Result<(), LaunchFailure>Expand description
Makes sure the container of plan is up, creating it when it has never existed and starting
it when it is only stopped.
A plain shell container is made from the base image, which a machine that has never built a profile does not have yet; it is built here first, so the first tab ever opened comes up rather than failing with “no such image”. A tab has no log, so the build’s own lines go nowhere and the tab shows that it is starting for as long as the build takes; a failure is shown with the engine’s words like any other. A profile container is made from the profile’s own image, which the profiles screen builds, so nothing is built here for one.
A profile container’s home volume is made along with the container, and a home made here is given the profile’s stored login before the container starts, so the first tab opened in a workspace does not ask for a login that was made already. A home that was there before the container is left as it is: it is the workspace’s own copy, and only the person may have it rewritten.
A container takes its mounts and its network when it is made, so a stopped container made
from another plan than this one (its PLAN_LABEL says so) is made again: removed and
created anew, which keeps every named volume and so the home with the harness’s login,
history and settings in it. What was only in the container itself, outside the home and the
workspace’s folders, goes with it, as it does when the container is removed by hand. A running
container is never made again, because tabs are working in it; it keeps its old plan until
it is next stopped, which happens by the latest when no QCode is open.
A frozen container is woken instead, for the same reason and with more to lose: it holds every tab of the profile, each with its own process and its own terminal, so a person coming back to it finds the work exactly as it was. Making it again would end all of them at once, so an engine that will not wake it is a failure the person is shown rather than a container QCode throws away and makes anew.
This runs engine commands and waits for them, so it belongs on a background thread: give it
to Command::perform, never to update or view.
§Errors
The engine’s own words when it cannot be started, or refuses to build the base image, to create or start the container, or to copy the login in; the machine’s when the bridge’s folder cannot be made.