Administration

Running as a service

How raftdb-server install-service sets up a systemd unit or a Windows startup task, what the unit does, how to remove it, and what exists for raftdb-mysql and raftdb-watch.

raftdb-server install-service#

Syntax#

raftdb-server install-service [--profile NAME] [--config FILE] [--user NAME] [--no-start] [--print]
raftdb-server uninstall-service

Options#

OptionMeaningDefault
--profile NAMEThe profile for a new settings file (single, primary, replica).single
--config FILEUse this existing settings file instead of the standard one.the standard file
--user NAMEThe system user the service runs as (Linux).raftdb
--no-startInstall only; do not start.start
--printShow exactly what would be done, without doing it. Needs no administrator rights.do it

Linux (systemd)#

Run it as root (for example sudo raftdb-server install-service). It:

  1. Creates the system user raftdb (no login).
  2. Creates the data folder /var/lib/raftdb (mode 750).
  3. Creates /etc/raftdb/raftdb.conf only if missing (mode 640, group raftdb; from init_text for the profile). An existing file is never changed.
  4. Copies the binary to /usr/local/bin/raftdb-server.
  5. Writes /etc/systemd/system/raftdb.service, checks the settings (a new replica or primary file still has placeholders: it is installed but not started and says what to edit), enables and starts the service, waits until the port answers and prints the address and sudo cat /var/lib/raftdb/admin.password.

The unit restarts on failure and is sandboxed: no capabilities, no new privileges, the file system read-only except the data folder, no devices or kernel settings, only IP and Unix sockets, no writable-and-executable memory. systemd-analyze security rated the first version 8.3 (EXPOSED) and the current one 3.0 (OK) (D45).

Manage it with the usual commands:

sudo systemctl status raftdb
sudo journalctl -u raftdb
sudo systemctl restart raftdb

Windows#

The same command registers a startup task named Raft DB Server in Task Scheduler (runs as SYSTEM at boot) with the files in %ProgramData%\RaftDB. It is a startup task and not a Windows service, because a real service must speak the Service Control Manager protocol and that needs foreign calls the engine does not have. The decision (D45) says to revisit it if a customer needs a true service. It is not documented whether the task restarts the server after a crash; run raftdb-watch with a restart_command that restarts it if you need that.

Uninstall#

raftdb-server uninstall-service removes the unit or task. Data and settings stay.

Not done#

Packages (deb, rpm, MSI), a true Windows service, and the watcher reading raftdb.conf.

raftdb-mysql and raftdb-watch#

install-service installs only raftdb-server. For the others:

ProgramWhat exists
raftdb-watchAn example unit for it (Restart=always, a raftdbwatch user) and an example raftdb.service for a server it watches (--dir /var/lib/raftdb --addr 0.0.0.0:7480 --udp --user admin:CHANGE-ME --user watcher:CHANGE-ME-TOO:readwrite, Restart=on-failure, LimitNOFILE=65536). Edit both: the example passes passwords on the command line, which show in the process list.
raftdb-mysqlNothing. A unit of the same shape as raftdb.service that runs raftdb-mysql --config /etc/raftdb/mysql.conf works the same way, but none is shipped or tested. With embed, raftdb-mysql is the server process: do not also run raftdb-server on the embedded raftdb.conf.

If you run raftdb-mysql with embed, then it is the process to put under the service manager, and the raftdb-server install-service unit is not used (the two would fight over the data directory).

Checklist#

  • A system user that owns only the data directory.
  • Settings in a file, not in the unit's command line, so passwords stay out of the process list.
  • The watcher's restart_command matches how you start the process.
  • A raised open-files limit if you expect many connections (the example sets LimitNOFILE=65536); each connection uses two threads.

See also#