Add systemd configuration.

This commit is contained in:
Pieter Hollander 2024-03-25 10:59:36 +01:00
parent 06fad3b0ca
commit f32072e997
Signed by: pieter
SSH key fingerprint: SHA256:HbX+9cBXsop9SuvL+mELd29sK+7DehFfdVweFVDtMSg
2 changed files with 59 additions and 2 deletions

View file

@ -18,12 +18,30 @@ Preferably, run the Docker image using the Docker compose examples provided in t
Go to the [releases page](https://git.hollander.online/energy/opendtu-logger/releases) and download the most recent stable release.
#### Running example
#### Running the binary as local user
```sh
REMOTE_URL="opendtu:80" DB_URL="host=localhost port=5432 user=postgres password=secret dbname=dtu sslmode=disable" TIMESCALEDB_ENABLED="true" TZ="Europe/Amsterdam" ./opendtu-logger
```
#### Creating a more permanent setup on Linux using systemd
```sh
sudo adduser --system --group --disabled-login --home /opt/opendtu-logger opendtu-logger
sudo mkdir /opt/opendtu-logger
sudo mkdir /opt/opendtu-logger/data
sudo mv ./opendtu-logger /opt/opendtu-logger/
sudo chown -R opendtu-logger:opendtu-logger /opt/opendtu-logger
```
```sh
sudo nano /etc/systemd/system/opendtu-logger.service
```
Add the contents of `systemd/opendtu-logger.service` and alter the `REMOTE_URL` and `DB_URL` Environment variables to match your setup.
### PostgreSQL setup
The OpenDTU logger logs to a PostgreSQL database and optionally supports TimescaleDB. Create a separate database and user using the following commands.
@ -64,4 +82,4 @@ The `grafana` folder contains example dashboards.
## Known issues
- The logger will currently log every event posted by OpenDTU to the websocket. Checks still need to be added to determine the uniqueness of an event. For more information, see also [this OpenDTU Github issue](https://github.com/tbnobody/OpenDTU/issues/1800).
- Upon restart of the OpenDTU, OpenDTU Logger will need to be restarted manually as well. Automatic reconnection logic is a work in progress.
- Upon restart of the OpenDTU, OpenDTU Logger will need to be restarted manually as well. Automatic reconnection logic is a work in progress. Using the `systemd` service file provides a workaround for this.

View file

@ -0,0 +1,39 @@
GNU nano 7.2 /etc/systemd/system/opendtu-logger.service
[Unit]
Description=OpenDTU Logger
Documentation=https://git.hollander.online/energy/opendtu-logger
After=network.target auditd.service
# If using a PostgreSQL DB on the local machine, uncomment the following additional "After" and "Require" sections.
## PostgreSQL
# After=postgresql.service
# Requires=postgresql.service
[Service]
RestartSec=10s
Type=simple
User=opendtu-logger
Group=opendtu-logger
Environment="REMOTE_URL=opendtu.local:80"
Environment="DB_URL=host=localhost port=5432 user=postgres password=secret dbname=dtu sslmode=disable"
Environment="TIMESCALEDB_ENABLED=true"
Environment="TZ=Europe/Amsterdam"
WorkingDirectory=/opt/opendtu-logger/
ExecStart=/opt/opendtu-logger/opendtu-logger
Restart=always
# Isolate OpenDTU Logger from the rest of the system
PrivateTmp=true
PrivateDevices=true
ProtectHome=true
NoNewPrivileges=true
ProtectSystem=strict
# Only allow writes to the following directories
ReadWritePaths=/opt/opendtu-logger/data/
[Install]
WantedBy=multi-user.target