Füge Unterstützung für systemd hinzu, indem die systemd-Entwicklungslibraries in CMakeLists.txt und Installationsskripten für OpenSUSE und Ubuntu 22 integriert werden. Aktualisiere die yourpart-daemon.service-Datei für eine verbesserte Service-Verwaltung und implementiere die Benachrichtigung an systemd, wenn der Dienst bereit ist.

This commit is contained in:
Torsten Schulz (local)
2025-08-31 23:49:16 +02:00
committed by Torsten (PC)
parent 91420b9973
commit 8ba4566d23
5 changed files with 24 additions and 1 deletions

View File

@@ -92,6 +92,10 @@ target_include_directories(yourpart-daemon PRIVATE
${LWS_INCLUDE_DIRS}
)
# Find systemd
find_package(PkgConfig REQUIRED)
pkg_check_modules(SYSTEMD REQUIRED libsystemd)
# Link libraries
target_link_libraries(yourpart-daemon PRIVATE
${PostgreSQL_LIBRARIES}
@@ -100,6 +104,7 @@ target_link_libraries(yourpart-daemon PRIVATE
${LIBPQXX_LIBRARIES}
${LWS_LIBRARIES}
nlohmann_json::nlohmann_json
${SYSTEMD_LIBRARIES}
)
# Installation rules

View File

@@ -123,6 +123,10 @@ fi
log_info "Installiere nlohmann-json..."
sudo zypper install -y nlohmann_json-devel
# Installiere systemd development libraries
log_info "Installiere systemd development libraries..."
sudo zypper install -y systemd-devel
# Installiere PostgreSQL Server (falls nicht vorhanden)
log_info "Prüfe PostgreSQL Installation..."
if ! systemctl is-active --quiet postgresql; then

View File

@@ -110,6 +110,10 @@ apt install -y \
log_info "Installiere nlohmann-json..."
apt install -y nlohmann-json3-dev
# Installiere systemd development libraries
log_info "Installiere systemd development libraries..."
apt install -y libsystemd-dev
# Installiere PostgreSQL Server (falls nicht vorhanden)
log_info "Prüfe PostgreSQL Installation..."
if ! systemctl is-active --quiet postgresql; then

View File

@@ -17,6 +17,7 @@
#include <thread>
#include <vector>
#include <memory>
#include <systemd/sd-daemon.h>
std::atomic<bool> keepRunning(true);
@@ -65,6 +66,10 @@ int main() {
worker->startWorkerThread();
worker->enableWatchdog();
}
// Benachrichtige systemd, dass der Service bereit ist
sd_notify(0, "READY=1");
while (keepRunning) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}

View File

@@ -5,12 +5,17 @@ After=network.target postgresql.service
Wants=postgresql.service
[Service]
Type=simple
Type=notify
User=yourpart
Group=yourpart
WorkingDirectory=/opt/yourpart
ExecStart=/usr/local/bin/yourpart-daemon
ExecStop=/bin/kill -TERM $MAINPID
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGTERM
TimeoutStartSec=30
TimeoutStopSec=30
Restart=always
RestartSec=5
StandardOutput=journal