summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2023-11-20 12:25:44 +0100
committerToni Uhlig <matzeton@googlemail.com>2023-11-20 12:27:40 +0100
commitd5266b7f44e0b9c02ef1fc3166ba59431ab43230 (patch)
tree97231a3ff6e4b30715847e827fe0f8d07f4449ea
parent82934b7271ad11332cdc291188e6b51e9534c301 (diff)
Support simple config file reading via systemd environment file.
* cfg file path defaults to PREFIX/etc/default/ndpid Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--CMakeLists.txt11
-rw-r--r--packages/systemd/default.cfg2
-rw-r--r--packages/systemd/ndpid@.service12
-rw-r--r--packages/systemd/ndpid@.service.in14
-rw-r--r--packages/systemd/ndpisrvd.service.in (renamed from packages/systemd/ndpisrvd.service)4
5 files changed, 28 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 91ead84cd..c456bd196 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,6 +28,9 @@ set(CPACK_STRIP_FILES ON)
set(CPACK_PACKAGE_VERSION_MAJOR 1)
set(CPACK_PACKAGE_VERSION_MINOR 5)
set(CPACK_PACKAGE_VERSION_PATCH 0)
+# Note: CPACK_PACKAGING_INSTALL_PREFIX and CMAKE_INSTALL_PREFIX are *not* the same.
+# It is used only to ease environment file loading via systemd.
+set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
include(CPack)
include(CheckFunctionExists)
@@ -403,8 +406,12 @@ if(BUILD_EXAMPLES)
endif()
if(ENABLE_SYSTEMD)
- install(FILES packages/systemd/ndpisrvd.service DESTINATION lib/systemd/system)
- install(FILES packages/systemd/ndpid@.service DESTINATION lib/systemd/system)
+ configure_file(packages/systemd/ndpisrvd.service.in ndpisrvd.service @ONLY)
+ configure_file(packages/systemd/ndpid@.service.in ndpid@.service @ONLY)
+
+ install(FILES packages/systemd/default.cfg DESTINATION etc/default RENAME ndpid)
+ install(FILES "${CMAKE_BINARY_DIR}/ndpisrvd.service" DESTINATION lib/systemd/system)
+ install(FILES "${CMAKE_BINARY_DIR}/ndpid@.service" DESTINATION lib/systemd/system)
endif()
install(FILES config.h
diff --git a/packages/systemd/default.cfg b/packages/systemd/default.cfg
new file mode 100644
index 000000000..8598da168
--- /dev/null
+++ b/packages/systemd/default.cfg
@@ -0,0 +1,2 @@
+COLLECTOR_PATH=/var/run/ndpisrvd-collector
+NDPID_ARGS="-A -z"
diff --git a/packages/systemd/ndpid@.service b/packages/systemd/ndpid@.service
deleted file mode 100644
index ab8110111..000000000
--- a/packages/systemd/ndpid@.service
+++ /dev/null
@@ -1,12 +0,0 @@
-[Unit]
-Description=nDPId Service on interface %i
-After=ndpisrvd.service
-Requires=ndpisrvd.service
-
-[Service]
-Type=simple
-ExecStart=/usr/sbin/nDPId -i %i -A -z -c /var/run/ndpisrvd-collector
-Restart=on-failure
-
-[Install]
-WantedBy=multi-user.target
diff --git a/packages/systemd/ndpid@.service.in b/packages/systemd/ndpid@.service.in
new file mode 100644
index 000000000..cfbb4110f
--- /dev/null
+++ b/packages/systemd/ndpid@.service.in
@@ -0,0 +1,14 @@
+[Unit]
+Description=nDPId Service on interface %i
+After=ndpisrvd.service
+Requires=ndpisrvd.service
+
+[Service]
+Type=simple
+ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/nDPId $NDPID_ARGS -i %i -c ${COLLECTOR_PATH}
+Restart=on-failure
+Environment=COLLECTOR_PATH=/var/run/ndpisrvd-collector NDPID_ARGS="-A -z"
+EnvironmentFile=@CMAKE_INSTALL_PREFIX@/etc/default/ndpid
+
+[Install]
+WantedBy=multi-user.target
diff --git a/packages/systemd/ndpisrvd.service b/packages/systemd/ndpisrvd.service.in
index cc6bb83c7..0fd3ba8e7 100644
--- a/packages/systemd/ndpisrvd.service
+++ b/packages/systemd/ndpisrvd.service.in
@@ -4,9 +4,11 @@ After=network.target
[Service]
Type=simple
-ExecStart=/usr/bin/nDPIsrvd -c /var/run/ndpisrvd-collector
+ExecStart=@CMAKE_INSTALL_PREFIX@/bin/nDPIsrvd -c ${COLLECTOR_PATH}
ExecStopPost=/bin/rm -f /var/run/ndpisrvd-collector
Restart=on-failure
+Environment=COLLECTOR_PATH=/var/run/ndpisrvd-collector
+EnvironmentFile=@CMAKE_INSTALL_PREFIX@/etc/default/ndpid
[Install]
WantedBy=multi-user.target