# orca.pool_boot

> A module of morca's API.

How a machine the pool autoscaler made becomes a worker (#267): its startup script, and the UI's answer to its `/api/worker/boot`.

The script (`boot_script`, the machine's cloud-init user data) holds one
secret, the machine's own worker token, which orca revokes when it removes
the machine. With it the machine asks the UI for the rest, over TLS:
`boot_answer` gives the worker image (`ORCA_WORKER_IMAGE`, the server's
own), the login to pull it (`orca.registry`), and the variables a worker
needs to reach the bucket (`ORCA_WAREHOUSE`, `ORCA_LOGS`, the `AWS_*`
ones), as the UI's own environment has them. It answers only a token the
autoscaler made for a machine that's live, so a token someone made with
`orca worker-token create` gets nothing from it.

The machine then installs Docker if it hasn't it, logs in, and runs the
image as `orca worker --pool <pool> --name <machine>`, with run cgroups
(`docs/hetzner.md`, "A cgroup per run"). With `ORCA_POOL_WORKER_COMMAND`
set on the scheduler, the script runs that command as the worker instead
(tests, without Docker).

## Functions

### `boot_script`

```mojo
def boot_script(remote: String, pool: String, name: String, token: String, command: String = "") -> String
```

The startup script of machine `name` of `pool`: ask `remote` (the UI) for what it needs with `token`, then run the worker, in Docker or as `command` when given.

### `boot_answer`

```mojo
def boot_answer(mut db: State, worker: Int) -> String
```

The UI's answer to a machine's `/api/worker/boot`, for worker token `worker`: what its script needs, as JSON. Raises (the UI answers 403) for a token the autoscaler didn't make, or whose machine isn't live.

## Aliases

### `BOOT_PATH`

```mojo
comptime BOOT_PATH = "/api/worker/boot"
```

### `CREATED_BY`

```mojo
comptime CREATED_BY = "pool:"
```

`orca.workers.created_by` of a token the autoscaler made: `pool:<pool>`.

### `WORKER_IMAGE`

```mojo
comptime WORKER_IMAGE = "ORCA_WORKER_IMAGE"
```
