Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.

Commit 709355e

Browse files
committed
Add example systemd unit and documentation on using it
1 parent 0f700cb commit 709355e

File tree

6 files changed

+112
-1
lines changed

6 files changed

+112
-1
lines changed

Diff for: docs/deploy/hardware.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 4
2+
sidebar_position: 1
33
---
44

55
# Hardware

Diff for: docs/deploy/linux.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
# Deploying on Linux
6+
7+
## systemd
8+
9+
TigerBeetle includes an example [systemd unit](https://github.com/tigerbeetle/tigerbeetle/tree/main/tools/systemd/) for use with Linux systems that use systemd.
10+
The unit is configured to start a [single-node cluster](../quick-start/single-binary.md), so you may need to adjust it for other cluster configurations.
11+
Instructions to do so are in our GitHub repository.

Diff for: scripts/.cspell.json

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
"myscript",
8484
"nacks",
8585
"Nearline",
86+
"networkd",
87+
"nounset",
8688
"otherstuff",
8789
"paxos",
8890
"POCPOU",

Diff for: tools/systemd/README.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# systemd Service Unit
2+
3+
This is an example of a systemd service that runs TigerBeetle.
4+
You will likely have to adjust it if you're deploying TigerBeetle.
5+
6+
## Adjusting
7+
8+
You can adjust multiple aspects of this systemd service.
9+
Each specific adjustment is listed below with instructions.
10+
11+
It is not recommended to adjust some values directly in the service file.
12+
When this is the case, the instructions will ask you to instead use systemd's drop-in file support.
13+
Here's how to do that:
14+
15+
1. Install the service unit in systemd (usually by adding it to `/etc/systemd/system`).
16+
2. Create a drop-in file to override the environment variables.
17+
Run `systemctl edit tigerbeetle.service`.
18+
This will bring you to an editor with instructions.
19+
3. Add your overrides.
20+
Example:
21+
```
22+
[Service]
23+
Environment=TIGERBEETLE_CACHE_GRID_SIZE=4GB
24+
Environment=TIGERBEETLE_ADDRESSES=0.0.0.0:3001
25+
```
26+
27+
### Pre-start script
28+
29+
This service executes the `tigerbeetle-pre-start` script before starting TigerBeetle.
30+
This script is responsible for ensuring that a replica data file exists.
31+
It will create a data file if it doesn't exist.
32+
33+
The script assumes that `/bin/sh` exists and points to a POSIX-compliant shell, and the `test` utility is either built-in or in the script's search path.
34+
If this is not the case, adjust the script's shebang.
35+
36+
The service assumes that this script is installed in `/usr/local/bin`.
37+
If this is not the case, adjust the `ExecStartPre` line in `tigerbeetle.service`.
38+
39+
### TigerBeetle executable
40+
41+
The `tigerbeetle` executable is assumed to be installed in `/usr/local/bin`.
42+
If this is not the case, adjust both `tigerbeetle.service` and `tigerbeetle-pre-start` to use the correct location.
43+
44+
### Environment variables
45+
46+
This service uses environment variables to provide default values for a simple single-node cluster.
47+
To configure a different cluster structure, or a cluster with different values, adjust the values in the environment variables.
48+
It is **not recommended** to change these default values directly in the service file, because it may be important to revert to the default behavior later.
49+
Instead, use systemd's drop-in file support.
50+
51+
### State directory and replica data file path
52+
53+
This service configures a state directory, which means that systemd will make sure the directory is created before the service starts, and the directory will have the correct permissions.
54+
This is especially important because the service uses systemd's dynamic user capabilities.
55+
systemd forces the state directory to be in `/var/lib`, which means that this service will have its replica data file at `/var/lib/tigerbeetle/`.
56+
It is **not recommended** to adjust the state directory directly in the service file, because it may be important to revert to the default behavior later.
57+
Instead, use systemd's drop-in file support.
58+
If you do so, remember to also adjust the `TIGERBEETLE_DATA_FILE` environment variable, because it also hardcodes the `tigerbeetle` state directory value.
59+
60+
Due to systemd's dynamic user capabilities, the replica data file path will not be owned by any existing user of the system.
61+
62+
### Hardening configurations
63+
64+
Some hardening configurations are enabled for added security when running the service.
65+
It is **not recommended** to change these, since they have additional implications on all other configurations and values defined in this service file.
66+
If you wish to change those, you are expected to understand those implications and make any other adjustments accordingly.

Diff for: tools/systemd/tigerbeetle-pre-start.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
if ! test -e "${TIGERBEETLE_DATA_FILE}"; then
5+
/usr/local/bin/tigerbeetle format --cluster="${TIGERBEETLE_CLUSTER_ID}" --replica="${TIGERBEETLE_REPLICA_INDEX}" --replica-count="${TIGERBEETLE_REPLICA_COUNT}" "${TIGERBEETLE_DATA_FILE}"
6+
fi

Diff for: tools/systemd/tigerbeetle.service

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[Unit]
2+
Description=TigerBeetle Replica
3+
Documentation=https://docs.tigerbeetle.com/
4+
After=network-online.target
5+
Wants=network-online.target systemd-networkd-wait-online.service
6+
7+
[Service]
8+
DynamicUser=true
9+
DevicePolicy=closed
10+
ProtectHome=true
11+
StateDirectory=tigerbeetle
12+
StateDirectoryMode=700
13+
14+
Environment=TIGERBEETLE_CACHE_GRID_SIZE=1GB
15+
Environment=TIGERBEETLE_ADDRESSES=3001
16+
Environment=TIGERBEETLE_REPLICA_COUNT=1
17+
Environment=TIGERBEETLE_REPLICA_INDEX=0
18+
Environment=TIGERBEETLE_CLUSTER_ID=0
19+
Environment=TIGERBEETLE_DATA_FILE=%S/tigerbeetle/0_0.tigerbeetle
20+
21+
Type=exec
22+
ExecStartPre=/usr/local/bin/tigerbeetle-pre-start.sh
23+
ExecStart=/usr/local/bin/tigerbeetle start --cache-grid=${TIGERBEETLE_CACHE_GRID_SIZE} --addresses=${TIGERBEETLE_ADDRESSES} ${TIGERBEETLE_DATA_FILE}
24+
25+
[Install]
26+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)