Controlling Zino with systemd

This assumes:

  1. you have created a user zino

  2. the user zino has the home directory of /home/zino

  3. zino is installed in a virtualenv /home/zino/.zino

Copy the zino.service.example file, reproduced below, to /etc/systemd/system/zino.service.

[Unit]
Description=Zino
After=network.target

[Service]
User=zino
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
WorkingDirectory=/home/zino
ExecStart=/home/zino/.zino/bin/zino
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
SyslogIdentifier=zino

[Install]
WantedBy=multi-user.target

To make systemd aware of the new unit, you should run:

sudo systemctl daemon-reload

To enable the new unit to start automatically at system boot, run:

sudo systemctl enable zino

To start Zino in the background now, run:

sudo systemctl start zino

This starts Zino directly as the unprivileged zino user. Zino still needs to bind the SNMP trap port (UDP 162), and ports below 1024 normally require root. Rather than starting as root, the unit grants Zino the single Linux capability that permits binding a privileged port — CAP_NET_BIND_SERVICE — through the AmbientCapabilities directive, while CapabilityBoundingSet restricts the service to that one capability. This way Zino can listen on port 162 without ever running with root privileges.

If you would rather have Zino start as root and drop its privileges afterwards (for example on a system without AmbientCapabilities support), set user in the [process] section of zino.toml (see Process configuration) and change the unit to run as User=root instead.

Removing redundant timestamps in logs

When running under systemd, Zino’s log output is handled by systemd and is viewable through the journalctl program (e.g. journalctl -u zino -f to follow the logs continuously).

However, systemd will add its own timestamps to log lines it receives, while Zino’s default log format includes timestamps. It might therefore be desirable to change Zino’s log format when running under systemd. The default looks something like this:

zino.toml
 [logging.formatters.standard]
 format = "%(asctime)s - %(levelname)s - %(name)s (%(threadName)s) - %(message)s"

Which could easily be changed to this:

zino.toml
 [logging.formatters.standard]
 format = "%(levelname)s - %(name)s (%(threadName)s) - %(message)s"

See Configuring logging for more details on controlling Zino log output.