Running mimicd

Building the binary from source, running it against your own PostgreSQL, under systemd and on Kubernetes, and what a supervisor must do.

The quickstart runs mimicd and PostgreSQL with Docker Compose. This page runs the binary itself, against a PostgreSQL you provide.

Building from source

You need Go (the version mimicd/go.mod pins), the Rust toolchain the repository's rust-toolchain.toml pins, and a C compiler. From the repository's mimicd/ directory:

go run ./internal/tools/buildcore   # the document core, as a static library
go build -o mimicd ./cmd/mimicd
./mimicd version

buildcore builds the document core (Rust) only when its sources changed, and writes the hash of those sources beside the library; the server refuses to start with a library built from other sources. go build links it with cgo. A build made in a git checkout announces its commit in mimicd version; elsewhere, give it to the linker:

go build -ldflags "-X github.com/voidhashcom/mimic-db/mimicd/internal/version.commit=$(git rev-parse HEAD)" \
  -o mimicd ./cmd/mimicd

A value that is not a commit (12 to 64 hexadecimal digits) makes a binary that refuses to run.

Against your own PostgreSQL

Make a database and a role that owns it (no superuser needed), then start the server with the store's URL in its environment:

export MIMIC_POSTGRES_URL='postgres://mimicd:PASSWORD@db.example:5432/mimic?sslmode=verify-full'
mimicd serve --bootstrap-admin admin --bootstrap-password-file /etc/mimicd/admin-password

The first start founds the deployment: it applies the schema, records the deployment's name, and creates the superuser from the password file. Later starts need neither bootstrap option. mimicd serve --check prints the options in effect and where each came from, without opening anything. See Requirements for what the store must provide and Configuration for every option.

The public API listens on 0.0.0.0:7700, plain HTTP, unless the process serves TLS (see Network and TLS). The operations listener is on 127.0.0.1:7702:

mimicd probe          # exits 0 once http://127.0.0.1:7702/readyz answers 200

Under a supervisor

Whatever runs the process:

  • Restart it after a failure (exit code 1), but not after exit codes 2 and 5, which wait for an operator.
  • Give it time to stop. On SIGTERM it stops taking requests and hands its partitions over within drain-timeout (20 seconds by default). Give it 30 seconds or more before it is killed.
  • Keep secrets in files or the environment, never in flags.
  • Run it as an unprivileged user. It needs no capability and writes no file of its own.

systemd

There is no packaged unit file. The [Service] section below is an untested sketch of what a unit for mimicd serve needs: check it on your systems before you rely on it.

[Service]
# MIMIC_POSTGRES_URL, in a file readable by root alone.
EnvironmentFile=/etc/mimicd/env
ExecStart=/usr/local/bin/mimicd serve --config /etc/mimicd/mimicd.toml
ExecReload=/bin/kill -HUP $MAINPID
User=mimicd
Restart=on-failure
RestartPreventExitStatus=2 5
TimeoutStopSec=30
KillSignal=SIGTERM

systemctl reload then sends SIGHUP, which reads the options again (see Configuration).

Kubernetes

There is no Helm chart, and the guidance below has not been tested on Kubernetes: it follows from what the process needs. The image runs as a Deployment, not a StatefulSet: the process is stateless and needs no volume.

  • Replicas. Any number. With more than one, give each process an internal listener on the pod's address (--listen.internal, with --advertise.internal set to the pod's IP and port) and the same internal secret, from a Secret mounted as a file (--internal.secret-file).
  • The store's URL from a Secret, as MIMIC_POSTGRES_URL.
  • Probes. /readyz for readiness and /livez for liveness, on the operations port 7702.
  • Stopping. terminationGracePeriodSeconds of 30 or more.
  • Founding. mimicd serve --init-only may run as an init container or a Job before the Deployment: it founds the deployment and exits.
  • Security. The image runs as user 65532. Migration sandboxes need a security profile that lets them install a seccomp filter; see Security.

The server ignores the MIMIC_*_SERVICE_HOST and MIMIC_*_PORT* variables Kubernetes' service links inject.

Operator commands

mimicd admin connects to PostgreSQL, never to a process: run it wherever the store's URL and credentials are, with MIMIC_POSTGRES_URL set (and MIMIC_STORE for every other store). See Administration.