mxhop

Install · systemd

Run it as a system service

Two units ship with the repository, and the interesting one is the socket. systemd binds port 25 before mxhop starts and hands the open socket over, so the process itself never has to be privileged to get it — and a restart does not drop a single connection, because the socket stays bound across it.

  1. A user that owns nothing else

    useradd --system --no-create-home --shell /usr/sbin/nologin mxhop
    install -d -o mxhop -g mxhop -m 0750 /var/lib/mxhop/spool
    install -d -m 0755 /etc/mxhop

    The spool is 0750: queued mail is mail, and nothing else on the host needs to read it.

  2. Install the units

    curl -fsSL -o /etc/systemd/system/mxhop.socket \
      https://raw.githubusercontent.com/metronom72/mxhop/v0.3.0/deploy/mxhop.socket
    curl -fsSL -o /etc/systemd/system/mxhop.service \
      https://raw.githubusercontent.com/metronom72/mxhop/v0.3.0/deploy/mxhop.service
    systemctl daemon-reload
  3. Start the socket, then the service

    systemctl enable --now mxhop.socket
    systemctl enable --now mxhop.service
    systemctl status mxhop --no-pager
    ● mxhop.service - mxhop SMTP forwarder
         Active: active (running)
       TriggeredBy: ● mxhop.socket
        Process: ExecStartPre=/usr/local/bin/mxhop check (code=exited, status=0)

    That ExecStartPre is deliberate: a config that does not pass check stops the unit from starting rather than coming up half-configured. A bad edit means the old process keeps running, which is the failure you want.

  4. Watch it take mail

    journalctl -u mxhop -f -o cat
    listening on the socket systemd handed over address=0.0.0.0:25
    mxhop is accepting mail hostname=mx.example.com aliases=4 auth=dmarc

What the unit gives up

The service file is mostly a list of things mxhop is not allowed to do. A mail server is the most exposed thing on a host — it takes bytes from anyone, unauthenticated — so the sandbox is the interesting half of the unit.

DirectiveEffect
User=mxhopNever root. The only thing it needed root for was the socket, and systemd holds that.
CapabilityBoundingSet=CAP_NET_BIND_SERVICEOne capability in the bounding set, and with socket activation it does not even use it.
ProtectSystem=strictThe whole filesystem is read-only except ReadWritePaths=/var/lib/mxhop.
PrivateDevices=truePrivateTmp=trueNo device nodes, a private /tmp.
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIXIt speaks TCP and nothing else. No netlink, no packet sockets.
MemoryDenyWriteExecute=trueNo page is ever both writable and executable.
SystemCallFilter=@system-service~@privileged @resourcesA seccomp allowlist, minus the privileged and resource-control groups.
NoNewPrivileges=trueNo setuid binary can raise it, whatever ends up on the filesystem.
ProtectProc=invisibleIt cannot see other processes in /proc.

Check your own copy rather than taking this table's word for it: systemd-analyze security mxhop.service scores the unit and names anything left open.

Operating it

systemctl reload mxhop

Sends SIGHUP. mxhop re-reads the TLS certificate and logs its new SHA-256 fingerprint; new connections use it, open ones are untouched. This is the hook for a certificate renewal — no restart, no dropped session.

systemctl restart mxhop

Stops gracefully: no new connections, 25 seconds for open sessions to finish, 421 to anyone waiting on a command. The socket unit keeps port 25 bound throughout, so a sender connecting mid-restart waits rather than seeing a refusal.

systemctl stop mxhop.socket

Stop this too, or systemd starts the service again the moment a sender connects. Stopping only the service looks like it worked and is not what you meant.

mxhop health

Exit code 0 or 1, suitable for a monitor. Asks the service's own /healthz, so it reports what the running process thinks, not what the unit file says.

Certificate renewals: point your ACME client's deploy hook at systemctl reload mxhop. Without it mxhop keeps serving the expired certificate until something restarts it, and senders that require TLS will start deferring your mail — quietly, because a deferral is not an error anybody emails you about.