From 910bdc03fa245b9805f5aa0d285d3e9c52151636 Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Thu, 18 Sep 2025 16:24:29 +0330 Subject: [PATCH 1/4] cmake: execute daemon-reload and restart postinst in deb Signed-off-by: Amin Vakil --- CMakeLists.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60b3a044a96..efee7bbfbd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1485,9 +1485,10 @@ if(DPKG_PROGRAM) ${PROJECT_SOURCE_DIR}/cpack/debian/conffiles ) + set(LDCONFIG_SCRIPT_CMDS "") if(FLB_RUN_LDCONFIG) set(LDCONFIG_DIR ${FLB_INSTALL_LIBDIR}) - file(WRITE ${PROJECT_BINARY_DIR}/scripts/postinst " + set(LDCONFIG_SCRIPT_CMDS " mkdir -p /etc/ld.so.conf.d echo \"${LDCONFIG_DIR}\" > /etc/ld.so.conf.d/libfluent-bit.conf ldconfig @@ -1496,9 +1497,20 @@ ldconfig rm -f -- /etc/ld.so.conf.d/libfluent-bit.conf ldconfig ") - set(CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${PROJECT_BINARY_DIR}/scripts/postinst;${PROJECT_BINARY_DIR}/scripts/prerm") + list(APPEND CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${PROJECT_BINARY_DIR}/scripts/postinst;${PROJECT_BINARY_DIR}/scripts/prerm") endif(FLB_RUN_LDCONFIG) + file(WRITE ${PROJECT_BINARY_DIR}/scripts/postinst "#!/bin/sh +set -e +${LDCONFIG_SCRIPT_CMDS} +if [ \"\$1\" = \"configure\" ]; then + systemctl daemon-reload >/dev/null || true + systemctl try-restart ${FLB_OUT_NAME}.service >/dev/null || true +fi +") + + list(APPEND CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${PROJECT_BINARY_DIR}/scripts/postinst;${PROJECT_BINARY_DIR}/scripts/prerm") + endif() # RPM Generation information From ba29ff52440852116ba631a2b1f8a230baac50fa Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Sat, 20 Sep 2025 12:16:52 +0330 Subject: [PATCH 2/4] Improve systemd daemon-reload command by adding default Signed-off-by: Amin Vakil --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efee7bbfbd8..b6a95a0e772 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1504,7 +1504,7 @@ ldconfig set -e ${LDCONFIG_SCRIPT_CMDS} if [ \"\$1\" = \"configure\" ]; then - systemctl daemon-reload >/dev/null || true + systemctl --system daemon-reload >/dev/null || true systemctl try-restart ${FLB_OUT_NAME}.service >/dev/null || true fi ") From a712a28c611d7058f55641e6d06c7a72a1ff3fcb Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Sat, 20 Sep 2025 16:41:06 +0330 Subject: [PATCH 3/4] Put debian/postinst.in in separate file Signed-off-by: Amin Vakil --- CMakeLists.txt | 12 ++++-------- cpack/debian/postinst.in | 7 +++++++ 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 cpack/debian/postinst.in diff --git a/CMakeLists.txt b/CMakeLists.txt index b6a95a0e772..83b81611c38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1500,14 +1500,10 @@ ldconfig list(APPEND CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${PROJECT_BINARY_DIR}/scripts/postinst;${PROJECT_BINARY_DIR}/scripts/prerm") endif(FLB_RUN_LDCONFIG) - file(WRITE ${PROJECT_BINARY_DIR}/scripts/postinst "#!/bin/sh -set -e -${LDCONFIG_SCRIPT_CMDS} -if [ \"\$1\" = \"configure\" ]; then - systemctl --system daemon-reload >/dev/null || true - systemctl try-restart ${FLB_OUT_NAME}.service >/dev/null || true -fi -") + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cpack/debian/postinst.in + ${PROJECT_BINARY_DIR}/scripts/postinst + ) list(APPEND CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${PROJECT_BINARY_DIR}/scripts/postinst;${PROJECT_BINARY_DIR}/scripts/prerm") diff --git a/cpack/debian/postinst.in b/cpack/debian/postinst.in new file mode 100644 index 00000000000..64367b8c16d --- /dev/null +++ b/cpack/debian/postinst.in @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +@LDCONFIG_POSTINST_CMDS@ +if [ "$1" = "configure" ]; then + systemctl --system daemon-reload >/dev/null || true + systemctl try-restart @FLB_OUT_NAME@.service >/dev/null || true +fi From 3c3a7433dda58f012d794ed896d7a3a05c5b94b2 Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Sat, 20 Sep 2025 16:53:17 +0330 Subject: [PATCH 4/4] Execute systemd stuff if ran by systemd Signed-off-by: Amin Vakil --- cpack/debian/postinst.in | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cpack/debian/postinst.in b/cpack/debian/postinst.in index 64367b8c16d..78d22cdaa53 100644 --- a/cpack/debian/postinst.in +++ b/cpack/debian/postinst.in @@ -1,7 +1,9 @@ #!/bin/sh set -e @LDCONFIG_POSTINST_CMDS@ -if [ "$1" = "configure" ]; then - systemctl --system daemon-reload >/dev/null || true - systemctl try-restart @FLB_OUT_NAME@.service >/dev/null || true +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + if [ -d /run/systemd/system ]; then + systemctl --system daemon-reload >/dev/null || true + systemctl try-restart @FLB_OUT_NAME@.service >/dev/null || true + fi fi