From b85d158399f54ba40f21785cc37a686b04f3fe15 Mon Sep 17 00:00:00 2001 From: ahspw Date: Tue, 2 Jan 2024 09:28:35 +0330 Subject: [PATCH 1/4] CPACK: add auto generated dbhelper maintainer scripts Signed-off-by: ahspw --- CMakeLists.txt | 4 +++ conf/fluent-bit | 76 +++++++++++++++++++++++++++++++++++++++++++ cpack/debian/postinst | 35 ++++++++++++++++++++ cpack/debian/postrm | 27 +++++++++++++++ cpack/debian/prerm | 7 ++++ src/CMakeLists.txt | 5 +++ 6 files changed, 154 insertions(+) create mode 100755 conf/fluent-bit create mode 100755 cpack/debian/postinst create mode 100755 cpack/debian/postrm create mode 100755 cpack/debian/prerm diff --git a/CMakeLists.txt b/CMakeLists.txt index d54d87e021b..f9f23000313 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1127,6 +1127,7 @@ else() set(FLB_INSTALL_BINDIR ${CMAKE_INSTALL_FULL_BINDIR}) set(FLB_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${FLB_OUT_NAME}") set(FLB_INSTALL_CONFDIR "${CMAKE_INSTALL_SYSCONFDIR}/${FLB_OUT_NAME}/") + set(FLB_INSTALL_INITDIR "/etc/init.d/") set(FLB_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include") endif() @@ -1207,6 +1208,9 @@ if(DPKG_PROGRAM) set(CPACK_DEBIAN_RUNTIME_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") set(CPACK_DEBIAN_RUNTIME_PACKAGE_CONTROL_EXTRA ${PROJECT_SOURCE_DIR}/cpack/debian/conffiles + ${PROJECT_SOURCE_DIR}/cpack/debian/prerm + ${PROJECT_SOURCE_DIR}/cpack/debian/postinst + ${PROJECT_SOURCE_DIR}/cpack/debian/postrm ) if(FLB_RUN_LDCONFIG) diff --git a/conf/fluent-bit b/conf/fluent-bit new file mode 100755 index 00000000000..12d3ce73018 --- /dev/null +++ b/conf/fluent-bit @@ -0,0 +1,76 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: fluent-bit +# Required-Start: $local_fs $remote_fs $network $syslog $named +# Required-Stop: $local_fs $remote_fs $network $syslog $named +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts the fluent-bit service +# Description: starts fluent-bit using start-stop-daemon +### END INIT INFO + +PATH=/opt/fluent-bit/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/opt/fluent-bit/bin/fluent-bit +NAME=fluent-bit +DESC=fluent-bit + +start_fluent_bit() { + # Start the daemon/service + # + # Returns: + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + start-stop-daemon --start --quiet --exec $DAEMON 2>/dev/null || return 2 +} + +test_config() { + # Test the fluent_bit configuration + $DAEMON --dry-run -c /etc/fluent-bit/fluent-bit.conf +} + +stop_fluent_bit() { + # Stops the daemon/service + # + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --name $NAME +} + +case "$1" in + start) + start_fluent_bit + ;; + stop) + stop_fluent_bit + ;; + restart) + + # Check configuration before stopping fluent_bit + if ! test_config; then + exit $? + fi + + stop_fluent_bit + case "$?" in + 0|1) + start_fluent_bit + ;; + *) + # Failed to stop + ;; + esac + ;; + configtest|testconfig) + test_config + ;; + *) + echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2 + exit 3 + ;; +esac + diff --git a/cpack/debian/postinst b/cpack/debian/postinst new file mode 100755 index 00000000000..cb983832aff --- /dev/null +++ b/cpack/debian/postinst @@ -0,0 +1,35 @@ +#!/bin/sh + +set -e + +case "${1}" in + configure) + chmod +x /etc/init.d/fluent-bit + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + + ;; + + *) + echo "postinst called with unknown argument \`${1}'" >&2 + exit 1 + ;; +esac + +# Automatically added by dh_installinit/12.10 +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + if [ -x "/etc/init.d/fluent-bit" ]; then + update-rc.d fluent-bit defaults >/dev/null + if [ -n "$2" ]; then + _dh_action=restart + else + _dh_action=start + fi + invoke-rc.d fluent-bit $_dh_action || exit 1 + fi +fi +# End automatically added section + + +exit 0 diff --git a/cpack/debian/postrm b/cpack/debian/postrm new file mode 100755 index 00000000000..89e1fc9bf50 --- /dev/null +++ b/cpack/debian/postrm @@ -0,0 +1,27 @@ +#!/bin/sh + +set -e + +case "${1}" in + remove) + + ;; + + purge|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + + ;; + + *) + echo "postrm called with unknown argument \`${1}'" >&2 + exit 1 + ;; +esac + +# Automatically added by dh_installinit/12.10 +if [ "$1" = "purge" ] ; then + update-rc.d fluent-bit remove >/dev/null +fi +# End automatically added section + + +exit 0 diff --git a/cpack/debian/prerm b/cpack/debian/prerm new file mode 100755 index 00000000000..bd4514a6a64 --- /dev/null +++ b/cpack/debian/prerm @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +# Automatically added by dh_installinit/12.10 +if [ -x "/etc/init.d/fluent-bit" ] && [ "$1" = remove ]; then + invoke-rc.d fluent-bit stop || exit 1 +fi +# End automatically added section diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b6233d9f721..bb2090b1efc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -572,4 +572,9 @@ if(FLB_BINARY) COMPONENT binary DESTINATION ${FLB_INSTALL_CONFDIR}) + install(FILES + "${PROJECT_SOURCE_DIR}/conf/fluent-bit" + COMPONENT binary + DESTINATION ${FLB_INSTALL_INITDIR}) + endif() From b233b5a2e51cf899f53999318f002f962d73b648 Mon Sep 17 00:00:00 2001 From: ahspw Date: Tue, 2 Jan 2024 13:55:49 +0330 Subject: [PATCH 2/4] CPACK: resolve ci issue and dbhelper comments Signed-off-by: ahspw --- CMakeLists.txt | 1 + cpack/debian/postinst | 2 -- cpack/debian/postrm | 2 -- cpack/debian/prerm | 3 +-- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9f23000313..e870fd67654 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1122,6 +1122,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(FLB_INSTALL_BINDIR "bin") set(FLB_INSTALL_LIBDIR "lib") set(FLB_INSTALL_CONFDIR "conf") + set(FLB_INSTALL_INITDIR "init.d") set(FLB_INSTALL_INCLUDEDIR "include") else() set(FLB_INSTALL_BINDIR ${CMAKE_INSTALL_FULL_BINDIR}) diff --git a/cpack/debian/postinst b/cpack/debian/postinst index cb983832aff..8335c196384 100755 --- a/cpack/debian/postinst +++ b/cpack/debian/postinst @@ -17,7 +17,6 @@ case "${1}" in ;; esac -# Automatically added by dh_installinit/12.10 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -x "/etc/init.d/fluent-bit" ]; then update-rc.d fluent-bit defaults >/dev/null @@ -29,7 +28,6 @@ if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-decon invoke-rc.d fluent-bit $_dh_action || exit 1 fi fi -# End automatically added section exit 0 diff --git a/cpack/debian/postrm b/cpack/debian/postrm index 89e1fc9bf50..3ac41988b77 100755 --- a/cpack/debian/postrm +++ b/cpack/debian/postrm @@ -17,11 +17,9 @@ case "${1}" in ;; esac -# Automatically added by dh_installinit/12.10 if [ "$1" = "purge" ] ; then update-rc.d fluent-bit remove >/dev/null fi -# End automatically added section exit 0 diff --git a/cpack/debian/prerm b/cpack/debian/prerm index bd4514a6a64..50259eae318 100755 --- a/cpack/debian/prerm +++ b/cpack/debian/prerm @@ -1,7 +1,6 @@ #!/bin/sh set -e -# Automatically added by dh_installinit/12.10 + if [ -x "/etc/init.d/fluent-bit" ] && [ "$1" = remove ]; then invoke-rc.d fluent-bit stop || exit 1 fi -# End automatically added section From 682f61dd268f94cd9f48cfb92af27bdd9eae82ea Mon Sep 17 00:00:00 2001 From: ahspw Date: Tue, 9 Jan 2024 08:51:23 +0330 Subject: [PATCH 3/4] CPACK: update main script for shellcheck Signed-off-by: ahspw --- conf/fluent-bit | 1 - 1 file changed, 1 deletion(-) diff --git a/conf/fluent-bit b/conf/fluent-bit index 12d3ce73018..01ca5ae4778 100755 --- a/conf/fluent-bit +++ b/conf/fluent-bit @@ -13,7 +13,6 @@ PATH=/opt/fluent-bit/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/opt/fluent-bit/bin/fluent-bit NAME=fluent-bit -DESC=fluent-bit start_fluent_bit() { # Start the daemon/service From 9dedf5a936cf34880db1e0a986926b14a08c29fc Mon Sep 17 00:00:00 2001 From: ahspw Date: Thu, 25 Jan 2024 22:41:32 +0330 Subject: [PATCH 4/4] CPACK: update main script for shellcheck Signed-off-by: ahspw --- conf/fluent-bit | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/fluent-bit b/conf/fluent-bit index 01ca5ae4778..12d3ce73018 100755 --- a/conf/fluent-bit +++ b/conf/fluent-bit @@ -13,6 +13,7 @@ PATH=/opt/fluent-bit/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/opt/fluent-bit/bin/fluent-bit NAME=fluent-bit +DESC=fluent-bit start_fluent_bit() { # Start the daemon/service