Skip to main content

Module localserver

Module localserver 

Source
Expand description

teamcraft local: a test installation on one computer, for trying TeamCraft out without Docker or a database administrator. It runs a private PostgreSQL cluster and the server, both only on 127.0.0.1, with every file in one data directory:

<data dir>/postgres/        the cluster (initdb on the first start)
<data dir>/postgres.log     PostgreSQL's log
<data dir>/db-password      the generated database password (0600)
<data dir>/vault/           the file vault

The PostgreSQL programs come from the release bundle (postgresql/bin next to the executable, as the desktop app’s with local server installers ship it), from --pg-bin, or from an installation on this computer. The cluster gets its own free port and no Unix socket; it uses scram-sha-256 with a random password, so other accounts on the computer cannot connect. The desktop app starts this command for Try TeamCraft on this computer (desktop/src/localserver.rs). Never for production: one user’s laptop, no backups, no TLS.

Structs§

Cluster
The running PostgreSQL cluster of a local installation.

Constants§

BUNDLED_PG_DIR
The directory the release bundles put the PostgreSQL programs in, next to the teamcraft executable (postgresql/bin/initdb, …).
DB_NAME
DB_USER
Database role and database of the local installation.
DEFAULT_PORT
HTTP port when none is given (the port of every other quick start).
SIDECAR_NAME
The name of this binary in the desktop downloads with local server (teamcraft-server[.exe] next to the app; desktop/src/localserver.rs).

Functions§

default_data_dir
Where the data lives when no --data-dir is given: the per-user data directory of the operating system, so that the desktop app and the command line share one installation.
find_pg_bin
The first candidate that holds initdb, pg_ctl and postgres.
free_port
A free TCP port on 127.0.0.1 (asked from the operating system).
is_pg_bin
Whether dir holds the programs teamcraft local runs.
local_conf
The settings of one start, written to teamcraft-local.conf in the cluster: only 127.0.0.1, the given port, no Unix socket (nothing in /tmp, no socket directory that would need root).
local_variables
The configuration variables of the local installation. They replace the same variables (and their _FILE forms) from the environment; see overlay_lookup.
overlay_lookup
A lookup for crate::config::Config::from_lookup: the local variables win, their _FILE forms and the database URLs are hidden, everything else (an assistant key, OIDC, …) comes from env.
pg_bin_candidates
The directories searched for the PostgreSQL programs, in order: --pg-bin; the bundle next to the executable (and in the macOS app’s Resources); PATH; the usual installation directories (Debian/Ubuntu /usr/lib/postgresql/<n>/bin, Homebrew, Postgres.app, the Windows installer), newest version first.
remove_port_file
Removes the port file again (after the cluster stopped).
running_instance
The port of another teamcraft local that still serves this data directory: its port file names a port whose /readyz answers like TeamCraft. Starting a second one would stop its PostgreSQL (it looks left running), so the caller refuses instead. A port file left behind by a killed instance does not count.
stdin_closed
Resolves when standard input reaches its end (or fails). The desktop app starts teamcraft local --exit-with-stdin with a pipe it never writes to: when the app ends – also when it crashes or is killed – the pipe closes and the server and PostgreSQL shut down cleanly. A plain thread, not a blocking tokio task: the runtime would wait for it at shutdown.
write_port_file
Records the HTTP port of this instance in the data directory.