Linux (systemd)
Run ndb as a system service on a Linux host: one binary, one ndb user, one unit. This is the simplest way on a plain VM.
Install
bash
curl -fsSL https://ndb.clowk.in/install.sh | sudo bash -s -- --systemdWith --systemd the script also:
- creates the
ndbuser and group; - creates
/var/lib/ndb(data) and/etc/ndb/ndb.yml(config). It never overwrites an existingndb.yml; - installs and starts
ndb.service.
Without --systemd it installs only the binary:
bash
curl -fsSL https://ndb.clowk.in/install.sh | bash- The script checks the sha256 of the release.
NDB_VERSION=0.1.2pins a version.NDB_INSTALL_DIRsets the binary dir (default/usr/local/bin, else~/.local/bin).
The unit
The unit is deploy/systemd/ndb.service:
ini
[Service]
User=ndb
Group=ndb
ExecStart=/usr/local/bin/ndb
Restart=on-failure
TimeoutStopSec=40
StateDirectory=ndb
RuntimeDirectory=ndb
NoNewPrivileges=true
ProtectSystem=strict
ReadWritePaths=/var/lib/ndb /run/ndbStateDirectoryandRuntimeDirectorycreate/var/lib/ndband/run/ndb, owned byndb.- No flags: the daemon reads
/etc/ndb/ndb.ymland makes the socket/run/ndb/ndb.sockwith mode0660, so apps in thendbgroup can open it. Add the app user to the group:usermod -aG ndb <app-user>. TimeoutStopSec=40: the daemon waits up to 30 s for running requests on SIGTERM.
The config is deploy/systemd/ndb.yml. data_dir must be /var/lib/ndb and listen.unix must be /run/ndb/ndb.sock, to match the unit:
yaml
data_dir: /var/lib/ndb
listen:
unix: /run/ndb/ndb.sockAdd collections and the other keys from Configuration.
Day to day
bash
systemctl status ndb
journalctl -u ndb -f
curl --unix-socket /run/ndb/ndb.sock http://ndb/_health
ndb statsTCP and token
To serve apps on other hosts, listen on a private address and require a token:
bash
head -c 32 /dev/urandom | base64 > /etc/ndb/token
chown ndb:ndb /etc/ndb/token && chmod 600 /etc/ndb/token
systemctl edit ndb # ExecStart=... -tcp 10.10.0.1:7070 -token-file /etc/ndb/tokenNever listen on 0.0.0.0 or a public IP. The full setup with WireGuard is Cross-VM.
Upgrade and remove
- Upgrade: take a backup, run the install command again (or with
NDB_VERSION), thensystemctl restart ndb. - Remove:
curl -fsSL https://ndb.clowk.in/uninstall.sh | sudo bash -s -- --systemdstops and removes the unit and keeps the data. Add--purgeto delete/var/lib/ndb,/etc/ndband the user.