How it works
A workspace has a short life with four commands: lo new, lo up, lo down and lo rm. This page tells the actions of each command and their order. Use the page to understand the output of lo, and to find the reason for a failure.
The records of lo new
Section titled “The records of lo new”lo new records a workspace and starts nothing. It does not make a worktree, a container or a process. The command makes these records:
- The name of the workspace, a short random ID and a slug of the name. The slug is the name in a form that is safe for host names and for file names.
- The template, and the mode of the workspace:
templateforlo new,worktreeforlo upin a git worktree. - One source for each repository that a service uses.
lo newfetchesoriginof each repository, then selects the ref. It uses the ref that you give, the branch that--matchfinds, or the default ref of the template. - One unit for each service and for each resource server. Each unit keeps the engine that the machine settings select now. A resource keeps its isolation.
- The
--envoverrides and the shared instances that the workspace uses.
The workspace has the status created. Template errors, an unknown ref and a name that a different workspace uses stop the command before it records anything.
The actions of lo up
Section titled “The actions of lo up”lo up makes the workspace run. It holds a lock on the workspace, so two commands cannot change the same workspace at the same time. The next sections follow the order of the actions.
Before anything starts
Section titled “Before anything starts”lo uplocks the workspace. It compares the records with the machine: an engine can say that a unit stopped, or a worktree can be gone. If a source directory is gone, the status isbrokenandlo upstops with the command to repair it.lo upcompares the memory and the disk that the units use with the free memory and free disk of the machine. The units use the average of the earlier runs. If the machine is short,lo upshows a prompt. Use--yesto start without the prompt.lo upadds the units that the template got afterlo new, and sets the status tostarting.lo upallocates a host port for each unit that listens. A port comes from the range in the machine settings. It is free on the machine at that time, and no other workspace holds it. The workspace keeps the port untillo rm.
Sources
Section titled “Sources”For each source, lo up makes a git worktree in the localspace home, in worktrees/<workspace>/<repository>. It reuses a worktree that it made before. The worktree is an owned worktree. localspace removes only an owned worktree.
- If a worktree of the user has the branch,
lo updoes not make a copy. The service runs from that worktree, and localspace did not make it. - A source that uses the default ref is a snapshot with no branch.
lo upmoves the snapshot to the current commit oforigin, only if the snapshot has no unsaved work. - In worktree mode, the service runs from the worktree where you ran
lo up. localspace did not make it.
Resources, shared instances and services
Section titled “Resources, shared instances and services”lo up starts the shared instances that the workspace uses, in reference order. With --service, it starts only the shared instances that the selected services must have: the items in their depends_on, or the services that a service without depends_on references. It then starts the resources in alphabetical order. Last, it starts the services. A service starts after the items in its depends_on. A service without depends_on starts after the services that it references.
A resource with instance isolation starts a server. A resource with database isolation makes a database on a server that workspaces use together. The server starts if it does not run. The provider then makes the database, or finds the one that carries the marker of the workspace.
For each service, lo up does these actions in order:
- Resolve the environment variables. The command replaces each reference with a value for this workspace. It reads the secrets from the secret store. A container and a host process get different addresses for the same reference.
- Do nothing more if the engine says that the unit runs.
- Run the
setupcommand. A host process runs it in the directory of the service. A container runs it in a container that the engine removes afterward. - Run the seed command of each resource that this service seeds, if the resource has no data from a seed.
- Start the unit with the engine that the workspace keeps. A container is built first.
- Record the public URL of the service, if the service is exposed.
- Wait until the unit is ready.
A unit is ready when its host port accepts connections. A ready setting can change this check to an HTTP path or to a command. The wait stops after 120 seconds, and the unit is failed.
A failed unit does not stop the other units. lo up keeps going, and the result lists the units that failed. Read their logs with lo logs. The one exception is depends_on: a service does not start if an item in its depends_on failed.
After the units start
Section titled “After the units start”lo up gives the routes of the exposed services to the proxy. The proxy then serves the public URLs. Last, lo up sets the status of the workspace.
| Status | Meaning |
|---|---|
up |
All services run and all resources are ready. |
partial |
Some units run and some do not. |
down |
No service runs. |
localspace keeps its state in a database in the localspace home. The state has the workspaces, the sources, the units, the ports, the resources and an event for each change. The dashboard and lo read the same state.
The state is a record, and the machine is the truth. Before each read, the core compares the two. If an engine says that a unit stopped, the core records the unit as exited or missing. If a command was killed during lo up, the core records the units as the engine shows them. A workspace with a worktree that is gone gets the status broken.
| Item | Statuses |
|---|---|
| Workspace | created, starting, up, partial, down, broken |
| Unit | starting, running, stopping, stopped, restarting, failed, exited, missing |
A unit is a service or a resource server that an engine runs. The state has a handle for each unit that started. The handle is a small map that the engine gives. The engine uses it to find the container or the process again in a different command. The core treats it as opaque data.
The workspace keeps the engine of each unit from lo new. If you change the engine in the machine settings, the change is only for new workspaces. A workspace uses the engine that it keeps until you remove it.
The actions of lo down
Section titled “The actions of lo down”lo down stops the units and removes nothing. It keeps the worktrees, the data of the resources, the ports and the records. It stops the shared instances that no other running workspace uses. It then updates the routes of the proxy, and the status is down.
lo down --service <name> stops only the services that you name. The status is then partial.
The actions of lo rm
Section titled “The actions of lo rm”lo rm removes a workspace and the things that localspace made for it.
- Refuse if an owned worktree has work that is not saved. See safety.
- Release the ports that
lo checkoutbound to the workspace. - Stop and remove all units, and drop all resources. The provider of a resource removes the database, the bucket or the volume of the workspace.
- Remove the networks and the volumes that carry the owner label of the workspace.
- Remove the owned worktrees.
- Delete the records of the workspace. The events stay as a log.