Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1543,9 +1543,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
Expand All @@ -1554,9 +1555,19 @@ 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)

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cpack/debian/postinst.in"
"${PROJECT_BINARY_DIR}/scripts/postinst"
)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E chmod +x
"${PROJECT_BINARY_DIR}/scripts/postinst"
)

list(APPEND CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA "${PROJECT_BINARY_DIR}/scripts/postinst")
endif()

# RPM Generation information
Expand Down
9 changes: 9 additions & 0 deletions cpack/debian/postinst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e
@LDCONFIG_SCRIPT_CMDS@
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 @[email protected] >/dev/null || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not good because:

📜 Debian Policy(9.3.3)

This postinst should not start or restart services unconditionally says that:

Maintainer scripts for packages including init scripts must use update-rc.d as described below to interact with the service manager for requests such as enabling or disabling services. They should use invoke-rc.d as described below to invoke init scripts for requests such as starting and stopping service.

Directly managing the /etc/rc?.d links and directly invoking the /etc/init.d/ init scripts should be done only by packages providing the init script subsystem (such as init-system-helpers).

So, this sequence in postinst is somewhat dangerous.

The below postinst would be ideal to handle this issue:

#!/bin/sh
set -e

SERVICE="@FLB_OUT_NAME@"

case "$1" in
    configure)
        if [ -d /run/systemd/system ]; then
            deb-systemd-helper daemon-reload || true

            if deb-systemd-helper --quiet is-enabled "$SERVICE.service"; then
                invoke-rc.d "$SERVICE" reload || true
            fi
        fi
        ;;
esac

exit 0

fi
fi
Loading