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:
committed by
Torsten (PC)
parent
91420b9973
commit
8ba4566d23
@@ -92,6 +92,10 @@ target_include_directories(yourpart-daemon PRIVATE
|
|||||||
${LWS_INCLUDE_DIRS}
|
${LWS_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Find systemd
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(SYSTEMD REQUIRED libsystemd)
|
||||||
|
|
||||||
# Link libraries
|
# Link libraries
|
||||||
target_link_libraries(yourpart-daemon PRIVATE
|
target_link_libraries(yourpart-daemon PRIVATE
|
||||||
${PostgreSQL_LIBRARIES}
|
${PostgreSQL_LIBRARIES}
|
||||||
@@ -100,6 +104,7 @@ target_link_libraries(yourpart-daemon PRIVATE
|
|||||||
${LIBPQXX_LIBRARIES}
|
${LIBPQXX_LIBRARIES}
|
||||||
${LWS_LIBRARIES}
|
${LWS_LIBRARIES}
|
||||||
nlohmann_json::nlohmann_json
|
nlohmann_json::nlohmann_json
|
||||||
|
${SYSTEMD_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Installation rules
|
# Installation rules
|
||||||
|
|||||||
@@ -123,6 +123,10 @@ fi
|
|||||||
log_info "Installiere nlohmann-json..."
|
log_info "Installiere nlohmann-json..."
|
||||||
sudo zypper install -y nlohmann_json-devel
|
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)
|
# Installiere PostgreSQL Server (falls nicht vorhanden)
|
||||||
log_info "Prüfe PostgreSQL Installation..."
|
log_info "Prüfe PostgreSQL Installation..."
|
||||||
if ! systemctl is-active --quiet postgresql; then
|
if ! systemctl is-active --quiet postgresql; then
|
||||||
|
|||||||
@@ -110,6 +110,10 @@ apt install -y \
|
|||||||
log_info "Installiere nlohmann-json..."
|
log_info "Installiere nlohmann-json..."
|
||||||
apt install -y nlohmann-json3-dev
|
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)
|
# Installiere PostgreSQL Server (falls nicht vorhanden)
|
||||||
log_info "Prüfe PostgreSQL Installation..."
|
log_info "Prüfe PostgreSQL Installation..."
|
||||||
if ! systemctl is-active --quiet postgresql; then
|
if ! systemctl is-active --quiet postgresql; then
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <systemd/sd-daemon.h>
|
||||||
|
|
||||||
std::atomic<bool> keepRunning(true);
|
std::atomic<bool> keepRunning(true);
|
||||||
|
|
||||||
@@ -65,6 +66,10 @@ int main() {
|
|||||||
worker->startWorkerThread();
|
worker->startWorkerThread();
|
||||||
worker->enableWatchdog();
|
worker->enableWatchdog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Benachrichtige systemd, dass der Service bereit ist
|
||||||
|
sd_notify(0, "READY=1");
|
||||||
|
|
||||||
while (keepRunning) {
|
while (keepRunning) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,17 @@ After=network.target postgresql.service
|
|||||||
Wants=postgresql.service
|
Wants=postgresql.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=notify
|
||||||
User=yourpart
|
User=yourpart
|
||||||
Group=yourpart
|
Group=yourpart
|
||||||
WorkingDirectory=/opt/yourpart
|
WorkingDirectory=/opt/yourpart
|
||||||
ExecStart=/usr/local/bin/yourpart-daemon
|
ExecStart=/usr/local/bin/yourpart-daemon
|
||||||
|
ExecStop=/bin/kill -TERM $MAINPID
|
||||||
ExecReload=/bin/kill -HUP $MAINPID
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
KillMode=mixed
|
||||||
|
KillSignal=SIGTERM
|
||||||
|
TimeoutStartSec=30
|
||||||
|
TimeoutStopSec=30
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
StandardOutput=journal
|
StandardOutput=journal
|
||||||
|
|||||||
Reference in New Issue
Block a user