4. Installing

What goes on which host

HostInstall
Every application hostThe daemon emfor, a config, and a service definition (systemd unit or rc.d script).
Hosts that use a check of emfor-check (redis, MySQL, PostgreSQL, LDAP, DNS, RADIUS, SIP, Diameter, SMTP, AMQP, MongoDB, gRPC, QUIC)Also emfor-check. The packages always include it.
Hosts whose applications use a client librarylibemfor and the wrapper for the application’s language.
Hosts whose programs only use DNSNothing more. Forward the zone from the host resolver (chapter 10).

Install the daemon and every client library from the same emfor release, and upgrade them together. The client library contains the daemon’s own LMDB build; a mismatch makes lookups fail with UNAVAILABLE and a message that says so.

Packages: deb and rpm

The repository builds a deb and an rpm. They are not published anywhere and not signed; you build them yourself, in Docker:

$ packages/build.sh                         # for this machine's architecture
$ PLATFORM=linux/amd64 packages/build.sh    # for another one (slow if emulated)

The packages land in packages/dist/ as emfor_<version>-1_<arch>.deb and emfor-<version>-1.<arch>.rpm.

The binaries are built against glibc 2.31, so they run on Debian 11 and later, Ubuntu 20.04 and later, and RHEL 9 and its relatives.

What a package installs:

PathWhat
/usr/bin/emfor, /usr/bin/emfor-checkThe daemon and the plugin program. The default config path is /etc/emfor/emfor.toml.
/usr/lib/systemd/system/emfor.serviceThe hardened systemd unit (below).
/etc/emfor/emfor.tomlA config that only sets include_dir = "conf.d". Kept on upgrade.
/etc/emfor/conf.d/Your service files go here; a README explains it.
/usr/share/doc/emfor/The commented example config, the Prometheus rules in examples/prometheus/ and the manual in manual/.

The scripts create the user and group emfor and make /etc/emfor and /etc/emfor/conf.d owned by root with mode 0755. The store directory /var/lib/emfor is created by the unit (StateDirectory=emfor).

# dpkg -i emfor_0.8.0-1_amd64.deb      # Debian, Ubuntu: enabled and started at once
# rpm -i emfor-0.8.0-1.x86_64.rpm      # RHEL and relatives: not enabled
# vi /etc/emfor/conf.d/10-web.toml     # your services
# emfor check-config
# systemctl enable --now emfor         # rpm; for the deb: systemctl reload emfor
# emfor status
  • deb: dpkg -r keeps the config; dpkg -P removes the config and /var/lib/emfor. The user stays.
  • rpm: an upgrade restarts a running daemon. Since 0.7.0 the rpm marks /etc/emfor/emfor.toml as %config(noreplace): an upgrade keeps your changed file and writes the packaged one next to it as emfor.toml.rpmnew.

Both packages depend on ca-certificates, which https checks with verification need.

RHEL 8 and its relatives are not supported. The binary needs glibc 2.30 and RHEL 8 has 2.28; use RHEL 9 or later (the deb: Debian 11 or later).

What has been tested: the deb and the rpm in Debian 12 and Rocky Linux 9 containers on arm64 (install, remove, purge, upgrade over a changed config), the deb under systemd 252 as PID 1 in a Debian 12 container, and the rpm under systemd as PID 1 in a Rocky Linux 9 container (start, reload, stop, rpm -V, remove and reinstall, an upgrade from the previous release and back). Not tested: the packages on a real host (a container is not one), x86-64 packages, other distributions. The rpm was also run on Rocky Linux 9.9 in a virtual machine with SELinux enforcing (start, checks, reload; no denial) and the deb on Ubuntu 24.04 with AppArmor enabled (no denial); see chapter 13. See packages/README.md.

Without network access

The running daemon needs no network beyond the addresses it checks: backends are IP addresses, there is no update check and no telemetry, and the http check does not use a proxy. So the install is the problem, not the run.

  • Build where you have a network, install where you do not. Build the deb or rpm with packages/build.sh on a connected machine (above), copy the file, and install it with dpkg -i or rpm -i. Check the copy with sha256sum against the value you took at the build; the packages are not signed.
  • ca-certificates is a dependency of both packages. Bring it from your internal mirror. For a server whose certificate a private CA signed, point the check’s ca_file at the CA instead of installing it system-wide (chapter 6).
  • From source without a network is plain cargo: cargo vendor on a connected machine, copy the directory and Cargo.lock, and build with --locked --offline. The project does not ship a vendored tree, a bill of materials or signed releases yet, and this offline build has not been run for this manual.
  • Documents: the packages install this manual under /usr/share/doc/emfor/manual/, so it is on the host.

Building from source

You need Rust 1.85 or later (the 2024 edition). From a checkout or an unpacked source release:

$ cargo build --release --bin emfor --bin emfor-check
# install -m 0755 target/release/emfor target/release/emfor-check /usr/bin/

emfor-check is optional; install it only if you use its checks. The database drivers are linked into emfor-check only, not into the daemon or the client library.

The daemon does not look for emfor-check anywhere: a plugin’s command names its path (chapter 7). Where it is depends on how you installed it:

Installemfor-check
deb and rpm packages/usr/bin/emfor-check
FreeBSD port/usr/local/bin/emfor-check
From source, with the install line above/usr/bin/emfor-check
From source, with cargo install --root /usr/local (below)/usr/local/bin/emfor-check

The default config path

emfor reads /etc/emfor/emfor.toml unless --config names another file. The default is fixed at build time by the environment variable EMFOR_PREFIX:

EMFOR_PREFIXDefault config path
not set, empty, / or /usr/etc/emfor/emfor.toml
/usr/local/usr/local/etc/emfor/emfor.toml
/opt/emfor/opt/emfor/etc/emfor/emfor.toml
$ EMFOR_PREFIX=/usr/local cargo build --release --bin emfor

A relative prefix fails the build. emfor --help shows the path that was built in. Only the config path follows the prefix: the store stays at [store] path (default /var/lib/emfor/state.mdb), which is also where the clients look.

With cargo install, name each crate (the repository root is a workspace):

# EMFOR_PREFIX=/usr/local cargo install --locked --path crates/emfor-daemon --root /usr/local
# cargo install --locked --path crates/emfor-check --root /usr/local

The systemd unit

The packages install the unit; for a source install, copy examples/systemd/emfor.service, which runs /usr/local/bin/emfor (edit the three paths if you installed to /usr/bin):

# useradd --system --no-create-home --shell /usr/sbin/nologin emfor
# install -m 0644 examples/systemd/emfor.service /etc/systemd/system/emfor.service
# install -d -m 0755 /etc/emfor /etc/emfor/conf.d
# install -m 0644 my-emfor.toml /etc/emfor/emfor.toml
# emfor check-config
# systemctl daemon-reload
# systemctl enable --now emfor

What the unit does:

SettingEffect
User=emfor, Group=emforThe daemon runs unprivileged.
ExecStartPre=... check-configAn invalid config never starts.
ExecReload=... check-config then kill -HUPsystemctl reload emfor signals the daemon only when the config is valid.
Restart=on-failure, RestartPreventExitStatus=1 2A crash (including exit 70) is restarted; exit 1 (cannot start) and 2 (invalid config) are not, because a retry does not fix them.
StartLimitIntervalSec=60, StartLimitBurst=5After five failed starts in a minute the unit is failed until systemctl reset-failed emfor. New in 0.7.0.
StateDirectory=emfor, StateDirectoryMode=0755Creates /var/lib/emfor for the store, owned by emfor.
UMask=0027, ProtectProc=invisible, ProcSubset=pidNew in 0.7.0. The store files set their own modes regardless.
ProtectSystem=strict, NoNewPrivileges=yes, SystemCallFilter=@system-service and moreHardening. Plugins and exec checks run under the same limits.
LimitNOFILE=65536Checks, plugins and DNS connections all use file descriptors.
CapabilityBoundingSet=No capabilities. For DNS on port 53, replace it with CapabilityBoundingSet=CAP_NET_BIND_SERVICE and AmbientCapabilities=CAP_NET_BIND_SERVICE.

Things to know:

  • The file system is read-only for the daemon except /var/lib/emfor. A [store] path elsewhere needs ReadWritePaths= in a drop-in (systemctl edit emfor).
  • Do not use DynamicUser=: its state directory is not reachable by the applications.
  • MemoryDenyWriteExecute=yes is in the unit as a comment. You can turn it on if none of your plugins generates code at run time; it was tried with the daemon and the dns plugin on systemd 252.
  • The logs go to the journal: journalctl -u emfor.
  • A copy of the example unit made for an older release does not change by itself: compare it with the new one when you upgrade (chapter 15).

FreeBSD

emfor is in the FreeBSD ports tree as net-mgmt/emfor (version 0.8.0 at the time of writing). Install the package, or build the port:

# pkg install emfor
# make -C /usr/ports/net-mgmt/emfor install clean

packages/freebsd/ keeps a copy of the port for reference and for trying a release before it reaches the ports tree. It builds both programs with EMFOR_PREFIX=/usr/local, installs an rc.d script and a sample config, creates the emfor user, an empty /usr/local/etc/emfor/conf.d, and /var/db/emfor for the store.

# sysrc emfor_enable=YES
# service emfor start
# emfor status
rc.conf variableDefaultMeaning
emfor_enableNOStart at boot.
emfor_config/usr/local/etc/emfor/emfor.tomlThe config file.
emfor_useremforThe user the daemon runs as. It needs write access to the store’s directory.
  • service emfor configtest checks the config, service emfor reload checks it and then sends SIGHUP, and start refuses an invalid config.
  • The daemon runs under daemon(8), which starts it again 2 seconds after it exits. Its log goes to syslog with the tag emfor.
  • The plugin program is /usr/local/bin/emfor-check, not /usr/bin.
  • The sample config puts the store at /var/db/emfor/state.mdb, not the default. Give every application on the host EMFOR_STORE=/var/db/emfor/state.mdb.

The project itself has built and installed the port on FreeBSD 15.1-RELEASE (arm64, in a virtual machine) with make stage check-plist install; it has not run it on 13.x or 14.x, or on amd64 beyond the project’s CI.

Nix

The repository has a flake with two packages and a NixOS module. The flake is in 0.8.0 and later (0.7.1 does not have it). emfor is not in nixpkgs.

$ nix build github:embark-systems/emfor#emfor
$ nix build github:embark-systems/emfor#libemfor

emfor holds the daemon and emfor-check; libemfor is the C client library of Client libraries below. Build both from the same revision, as for any other install.

The module, nix/module.nix, writes emfor.toml from Nix settings, links it to /etc/emfor/emfor.toml, creates the emfor user and runs the daemon under the same hardened unit as the deb and rpm packages:

{
  inputs.emfor.url = "github:embark-systems/emfor";

  outputs = { nixpkgs, emfor, ... }: {
    nixosConfigurations.host = nixpkgs.lib.nixosSystem {
      modules = [
        emfor.nixosModules.default
        {
          services.emfor = {
            enable = true;
            settings = {
              site = "dc1";
              dns = { listen = [ "127.0.0.1:5300" ]; zone = "svc.emfor"; };
              services."api.svc.emfor" = {
                check = "tcp";
                backends = [ "10.0.0.1:8080" ];
              };
            };
          };
        }
      ];
    };
  };
}
  • settings takes the keys of emfor.toml (chapter 5). The generated file is in the Nix store, which every user can read: do not put a secret in it. Keys that name a file (the peer secret, a check’s password file) point at a file outside the store.
  • The unit runs emfor check-config before it starts and when it reloads. A change to settings reloads the daemon; it does not restart it.
  • The store is /var/lib/emfor/state.mdb. With the default file_mode the users of applications that use an emfor client have to be in the group set by services.emfor.group (emfor by default).

The flake was built in a nixos/nix container on aarch64 Linux without the Nix sandbox: both packages build, the daemon’s tests pass, and emfor check-config accepts the file the module generates. The project has not started the service on a NixOS machine, and has not tried x86-64 Linux or macOS.

Client libraries

Every client reads the store through libemfor, built from clients/rust with cargo-c. It contains emfor’s own LMDB build; a system liblmdb cannot read the store.

$ cargo install cargo-c
$ cd clients/rust
# cargo cinstall --release --features capi --prefix /usr/local

This installs libemfor.so (with the soname libemfor.so.0.7 for 0.7.x), libemfor.a, the header emfor.h and emfor.pc for pkg-config.

LanguageInstall
RustDepend on the emfor-client crate from the same release (clients/rust). No libemfor needed.
Clibemfor as above; build with cc app.c $(pkg-config --cflags --libs emfor).
Golibemfor, then go get github.com/embark-systems/emfor/clients/[email protected]. Needs cgo and pkg-config emfor.
Pythonlibemfor, then pip install clients/python (Python 3.9 or later; it uses ctypes). Set EMFOR_LIBRARY to the library’s path if it is outside the standard directories.
Perllibemfor, then in clients/perl: perl Makefile.PL && make -f Makefile.xs && make -f Makefile.xs install.
PHPlibemfor, then build the extension with phpize from a copy of clients/php (see chapter 9) and enable extension=emfor. PHP 8.1 or later.

Prefer the shared library: it exports only emfor_* symbols, so its LMDB cannot clash with another LMDB in the same process.

Chapter 9 shows how to use each one.

Built with Hugo
Theme Stack designed by Jimmy