From 8ba4566d2315809f2977603e239f65d6db0447c2 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Sun, 31 Aug 2025 23:49:16 +0200 Subject: [PATCH] =?UTF-8?q?F=C3=BCge=20Unterst=C3=BCtzung=20f=C3=BCr=20sys?= =?UTF-8?q?temd=20hinzu,=20indem=20die=20systemd-Entwicklungslibraries=20i?= =?UTF-8?q?n=20CMakeLists.txt=20und=20Installationsskripten=20f=C3=BCr=20O?= =?UTF-8?q?penSUSE=20und=20Ubuntu=2022=20integriert=20werden.=20Aktualisie?= =?UTF-8?q?re=20die=20yourpart-daemon.service-Datei=20f=C3=BCr=20eine=20ve?= =?UTF-8?q?rbesserte=20Service-Verwaltung=20und=20implementiere=20die=20Be?= =?UTF-8?q?nachrichtigung=20an=20systemd,=20wenn=20der=20Dienst=20bereit?= =?UTF-8?q?=20ist.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 5 +++++ install-dependencies-opensuse.sh | 4 ++++ install-dependencies-ubuntu22.sh | 4 ++++ src/main.cpp | 5 +++++ yourpart-daemon.service | 7 ++++++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a888453..67e5ba0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/install-dependencies-opensuse.sh b/install-dependencies-opensuse.sh index 9f24f89..a1cfa14 100755 --- a/install-dependencies-opensuse.sh +++ b/install-dependencies-opensuse.sh @@ -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 diff --git a/install-dependencies-ubuntu22.sh b/install-dependencies-ubuntu22.sh index 63ff4b3..835acbc 100755 --- a/install-dependencies-ubuntu22.sh +++ b/install-dependencies-ubuntu22.sh @@ -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 diff --git a/src/main.cpp b/src/main.cpp index 47cf890..c69db9b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include std::atomic 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)); } diff --git a/yourpart-daemon.service b/yourpart-daemon.service index 4633f4b..5f17c2c 100644 --- a/yourpart-daemon.service +++ b/yourpart-daemon.service @@ -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