v0.7.0
Menu

#Deployment

On Debian and Ubuntu, ferrite_db can be installed as a systemd service. The package is a .deb built by packaging/build-deb.sh in the repository. It has been installed and run under systemd in an Ubuntu 24.04 VM (crash restart, reboot, remove and purge, remote access with a token, SCRAM, TLS, certificate reload). It has not had wider testing than that.

#Install

The install script downloads the latest .deb from the GitHub releases and installs it with apt-get:

curl -fsSL https://raw.githubusercontent.com/LeSynz/ferrite_db/main/install.sh | sh

It needs apt, and uses sudo if you are not root. To install by hand, download ferrite-db_<arch>.deb from the releases page and run sudo apt-get install ./ferrite-db_<arch>.deb. To build it yourself:

packaging/build-deb.sh   # writes target/deb/ferrite-db_<version>_<arch>.deb

#What the package does

item where
binary /usr/bin/ferrite_db
systemd unit /lib/systemd/system/ferrite.service
config /etc/ferrite/ferrite.conf, owned root:ferrite, mode 0640
data /var/lib/ferrite, owned by ferrite, mode 0750

On first install the post-install script creates a system user and group ferrite (no home, no shell), sets up the directories, and enables and starts the service. This is safe because the default config listens on loopback. On an upgrade it restarts the service. Removing or purging the package never deletes /var/lib/ferrite or the ferrite user.

A fresh install listens on 127.0.0.1:7878 with no token and no users, so it is open to anyone on that machine. Make the first admin by connecting from the machine and sending createUser (after that every connection has to log in), or set a token first. See authentication.

#Config file

/etc/ferrite/ferrite.conf is one FERRITE_X=value per line, read by systemd as an EnvironmentFile. There is no quoting and no spaces around =. Restart after editing:

sudo systemctl restart ferrite

It is mode 0640 so a token in it stays private. The variables are the same as for running by hand:

variable meaning
FERRITE_ADDR listen address, default 127.0.0.1:7878. Anything but loopback needs a token
FERRITE_DATA data directory, set by the unit to /var/lib/ferrite. Change it only together with ReadWritePaths
FERRITE_TOKEN the admin token, 16 or more characters
FERRITE_TLS_CERT, FERRITE_TLS_KEY TLS certificate and key, see TLS
FERRITE_TLS_CLIENT_CA, FERRITE_TLS_CRL client certificate authority and revocation lists
FERRITE_SYNC group, or milliseconds between fsyncs, 0 for every write. See durability
FERRITE_MAX_MEMORY memory limit in MB, 0 for none. See memory and limits
FERRITE_REPLICATE_* make this a follower, see replication

Every setting is also listed in configuration. A command-line address or sync argument wins over the variable.

A non-loopback address without a token stops the server from starting, and the error is in the journal.

#The unit

[Service]
Type=simple
User=ferrite
Group=ferrite
Environment=FERRITE_DATA=/var/lib/ferrite
EnvironmentFile=-/etc/ferrite/ferrite.conf
ExecStart=/usr/bin/ferrite_db
Restart=on-failure
SuccessExitStatus=143
RestartSec=2
TimeoutStopSec=10
LimitNOFILE=65536
StateDirectory=ferrite
StateDirectoryMode=0750
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
ReadWritePaths=/var/lib/ferrite
  • It runs as the ferrite user, restarts after a crash, and exits cleanly on SIGTERM (exit status 143 counts as success). SIGINT and SIGTERM sync every log first.
  • ProtectSystem=strict makes the file system read-only except /var/lib/ferrite. Files the server only reads, such as TLS certificates in /etc/ferrite/tls/, are fine.
  • Add MemoryMax= above FERRITE_MAX_MEMORY plus headroom if you want one, for example 1536M for a limit of 1024.
  • EnvironmentFile=- means the file may be missing.

#Running it

systemctl status ferrite
journalctl -u ferrite -f
sudo systemctl restart ferrite
sudo systemctl stop ferrite

The log goes to the journal under the identifier ferrite. At start it prints the data directory and sync policy, the memory limit, and one recovered <name>: ... line per database.

#Without the package

Any Linux machine with a Rust toolchain can build and run the binary:

cargo build --release
FERRITE_DATA=/var/lib/ferrite ./target/release/ferrite_db 127.0.0.1:7878

The defaults are 127.0.0.1:7878 and a ferrite_data directory in the current directory. Nothing else is needed: the server has no config file of its own, only environment variables, and a few command-line arguments (the address, then the sync policy).

#Upgrading

Install the new .deb over the old one. The service is restarted and the logs are replayed. Read the durability note first: newer logs cannot be read by older binaries.