Kept commands (experiment)

Keep a command running in a Space: restarts, health checks, start on boot and logs.

These calls belong to the Child Spaces experiment (cua experiments enable child-spaces) for adding a service; listing, stopping and removing work either way. See Keep a command running.

Services#

Methods of Space.

Space.put_service#

Keeps a command running in this Space (replacing a service of that name): restarted by its policy when it ends or fails its health check, started when the Space boots, its output kept in a log file.

async def put_service(self, _def: SpaceServiceDef) -> SpaceServiceInfo
ParameterTypeDefault
defSpaceServiceDefrequired

Returns SpaceServiceInfo · Async · Raises CuaError

Space.kept_services#

This Space's services.

async def kept_services(self) -> List[SpaceServiceInfo]

Returns Vec<SpaceServiceInfo> · Async · Raises CuaError

Space.start_service#

Starts a stopped service.

async def start_service(self, name: str) -> SpaceServiceInfo
ParameterTypeDefault
nameStringrequired

Returns SpaceServiceInfo · Async · Raises CuaError

Space.stop_service#

Stops a service and keeps it stopped (also across a reboot).

async def stop_service(self, name: str) -> SpaceServiceInfo
ParameterTypeDefault
nameStringrequired

Returns SpaceServiceInfo · Async · Raises CuaError

Space.restart_service#

Restarts a service.

async def restart_service(self, name: str) -> SpaceServiceInfo
ParameterTypeDefault
nameStringrequired

Returns SpaceServiceInfo · Async · Raises CuaError

Space.delete_service#

Stops a service and forgets it (its logs go too).

async def delete_service(self, name: str) -> None
ParameterTypeDefault
nameStringrequired

Async · Raises CuaError

Space.service_logs#

The end of a service's log (tail_bytes None: 64 KiB).

async def service_logs(self, name: str, tail_bytes: Optional[int]) -> str
ParameterTypeDefault
nameStringrequired
tail_bytesOption<u64>required

Returns String · Async · Raises CuaError

SpaceServiceDef record#

A command a Space keeps running (Space.put_service).

FieldTypeDefaultDescription
nameStringName: lowercase letters, digits, -, _, . (1 to 63).
commandStringThe shell command line it runs.
envHashMap<String, String>[:]Extra environment.
cwdOption<String>NoneWorking directory.
restartOption<String>NoneWhen it is started again: always (default), on-failure or never.
probeOption<SpaceServiceProbe>NoneA health check; failing it restarts the service.
start_on_boot / startOnBootOption<bool>NoneStart it when the Space boots. None: yes.

SpaceServiceProbe record#

A health check: exactly one of http, tcp, command.

FieldTypeDefaultDescription
httpOption<String>NoneA URL that answers 2xx or 3xx.
tcpOption<String>Nonehost:port that accepts a TCP connection.
commandOption<String>NoneA shell command that exits 0 when healthy.
interval_secs / intervalSecsOption<u64>NoneSeconds between checks (default 10).
failuresOption<u32>NoneFailed checks in a row that restart it (default 3).

SpaceServiceInfo record#

A service and how it is doing (Space.services).

Returned by Space.kept_services, Space.put_service, Space.restart_service, Space.start_service, Space.stop_service.

FieldTypeDefaultDescription
nameStringName.
commandStringThe command line.
stateStringstarting, running, unhealthy, backoff, stopped, exited or failed.
pidu32Its process, while it runs.
restartsu32Starts after the first.
last_end / lastEndStringHow the last process ended, if one did.
probe_error / probeErrorStringThe last failed health check, if the last one failed.
restartStringalways, on-failure or never.
start_on_boot / startOnBootboolStarts when the Space boots.
log_path / logPathStringIts log file in the Space.