From 165c79e67b2606558e6fafdc37368a841afbdd6d2b79fa5ad9595178b0b7b7b8 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 23 Mar 2025 14:58:35 +0100 Subject: [PATCH] improve systemd unit file --- README.md | 3 +++ server/scripts/locationhub.service | 29 ++++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3aba7f6..4b7de0e 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,9 @@ Use `https://your.domain.tld/api/metrics` to retrieve useful insides for monitor ## Add a Location Tracker We use the [SenseCAP T1000-B](https://www.seeedstudio.com/SenseCAP-Card-Tracker-T1000-B-p-5698.html) from seeedstudio because of the fair price and multiple location providers. However, you can use any LoRaWAN-enabled tracker that is compatible with TTN and supports the required payload fields. +## Troubleshooting +Run `journalctl -u locationhub.service -f` to see log output. + ### Onboard SenseCAP T1000-B 1. Download and install the App [SenseCraft](https://play.google.com/store/apps/details?id=cc.seeed.sensecapmate) 2. Skip the user account at startup with `Skip` in the upper right corner diff --git a/server/scripts/locationhub.service b/server/scripts/locationhub.service index 7b3b7c0..91cdf56 100644 --- a/server/scripts/locationhub.service +++ b/server/scripts/locationhub.service @@ -1,22 +1,29 @@ [Unit] -Description=LocationHub +Description=LocationHub Service +Documentation=https://git.mosad.xyz/localhorst/LocationHub After=network.target systemd-networkd-wait-online.service mysqld.service [Service] Type=simple User=locationhub +Group=locationhub WorkingDirectory=/home/locationhub/git/LocationHub/server/ -ExecStart=/usr/bin/npm run dev + +# Combine commands for build and start +ExecStart=/bin/bash -c "/usr/bin/npm run build && /usr/bin/npm run start" + +# Restart policies Restart=on-failure -StandardOutput=append:/var/log/LocationHub.log -StandardError=append:/var/log/LocationHub.log +RestartSec=5s + +# Logging configuration +StandardOutput=journal +StandardError=journal +SyslogIdentifier=locationhub + +# Resource control (optional but helps stability) +MemoryLimit=512M +CPUQuota=50% [Install] WantedBy=multi-user.target -``` -Activate Systemd Job -``` -systemctl daemon-reload -systemctl enable locationhub.service -systemctl start locationhub.service -systemctl status locationhub.service \ No newline at end of file