From a4b0600383d8a0007fb55e4b536dfc2d3ad7e78c Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Wed, 9 Oct 2024 14:27:48 +0900 Subject: [PATCH 01/29] deb rpm: install missing local plugins during upgrade process deb: * preinst: detect locally installed plugins * collect plugin information via fluent-diagtool * postinst: install locally installed plugins * if network access is denied, giving up install plugins rpm: * %pre $1 == 2 (upgrade): detect locally installed plugins * collect plugin information via fluent-diagtool * %post $1 == 2 (upgrade): install locally installed plugins * if network access is denied, giving up install plugins Signed-off-by: Kentaro Hayashi --- .../fluent-package/deb/postinst | 29 ++++++++++- .../fluent-package/deb/preinst | 48 +++++++++++++++++++ fluent-package/yum/fluent-package.spec.in | 45 +++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100755 fluent-package/templates/package-scripts/fluent-package/deb/preinst diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postinst b/fluent-package/templates/package-scripts/fluent-package/deb/postinst index dee4c4a67..cc4e5c333 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postinst @@ -145,6 +145,32 @@ migration_from_v4_post_process() { fi } +local_plugin_migration=/tmp/<%= package_dir %>/.local_plugin_migration +local_base_plugins=/tmp/<%= package_dir %>/.local_base_plugins +local_missing_plugins=/tmp/<%= package_dir %>/.local_missing_plugins +install_missing_plugins() { + if [ -f $local_plugin_migration ]; then + echo "Checking network connectivity..." + if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then + echo "Can't install missing plugins automatically, please install the following plugins manually." + cat $local_plugin_migration + else + echo "Install missing plugins automatically..." + /usr/sbin/fluent-gem list | grep fluent-plugin | cut -d' ' -f1 > $local_base_plugins + # NOTE: Do not install already bundled plugins + diff -u $local_base_plugins $local_plugin_migration | grep '^+fluent' | sed -e 's/\+//' > $local_missing_plugins + if [ -s $local_missing_plugins ]; then + cat $local_missing_plugins | xargs sudo /usr/sbin/fluent-gem install --no-document + else + echo "No need to install missing plugins..." + fi + rm -f $local_base_plugins + rm -f $local_missing_plugins + fi + rm -f $local_plugin_migration + fi +} + case "$1" in configure) add_system_user @@ -152,7 +178,8 @@ case "$1" in migration_from_v4_main_process fixperms migration_from_v4_post_process - ;; + install_missing_plugins + ;; abort-upgrade|abort-deconfigure|abort-remove) : ;; diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/preinst b/fluent-package/templates/package-scripts/fluent-package/deb/preinst new file mode 100755 index 000000000..a4cf6b802 --- /dev/null +++ b/fluent-package/templates/package-scripts/fluent-package/deb/preinst @@ -0,0 +1,48 @@ +#!/bin/sh + +set -e + +# Summary of how this script can be called: +# * 'install' +# * 'install' +# * 'upgrade' +# * 'abort-upgrade' +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package. + +local_plugin_migration=/tmp/<%= package_dir %>/.local_plugin_migration +migrate_local_plugins() { + # collect manually installed plugins + archive_path=$(sudo /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp | tail -n 1 | cut -d' ' -f10) + local_gem_output=$(echo $archive_path | sed -e 's/diagout-//' -e 's/.tar.gz//')/output/gem_local_list.output + if [ -f $local_gem_output ]; then + if [ -s $local_gem_output ]; then + # If there are missing plugins, mark path to it + cp $local_gem_output $local_plugin_migration + fi + fi +} + +echo "preinst v6: $1" +echo "preinst v6 prevver: $2" + +case "$1" in + upgrade) + migrate_local_plugins + ;; + abort-upgrade) + ;; + install) + ;; + *) + echo "preinst called with unknown argument '$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index 0549d7bc7..d1356f5d8 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -32,6 +32,8 @@ %define v4migration_with_restart /tmp/@PACKAGE_DIR@/.v4migration_with_restart %define v4migration_old_rotate_config_saved /tmp/@PACKAGE_DIR@/.old_rotate_config %define v4migration_enabled_service /tmp/@PACKAGE_DIR@/.v4migration_enabled_service +%define local_plugin_migration /tmp/@PACKAGE_DIR@/.local_plugin_migration +%define local_base_plugins /tmp/@PACKAGE_DIR@/.base-plugins # Omit the brp-python-bytecompile automagic because post hook for ffi fails on AmazonLinux 2. %if %{_amazon_ver} == 2 @@ -186,6 +188,25 @@ else /usr/sbin/useradd --system --uid $TD_UID --gid $TD_GID --home-dir %{_localstatedir}/lib/@PACKAGE_DIR@ --shell /sbin/nologin --non-unique @SERVICE_NAME@ fi fi +if [ $1 -eq 2 ]; then + # collect manually installed plugins during upgrading + archive_path=$(sudo /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp | tail -n 1 | cut -d' ' -f10) + local_gem_output=$(echo $archive_path | sed -e 's/diagout-//' -e 's/.tar.gz//')/output/gem_local_list.output + if [ -f $local_gem_output ]; then + if [ -s $local_gem_output ]; then + # If there are missing plugins, mark path to it + echo "Detected missing plugins..." + cp $local_gem_output %{local_plugin_migration} + else + echo "Missing $local_gem_output" + fi + else + echo "Missing $local_gem_output to check locally installed plugins." + fi + rm -f $archive_path + archive_dir=$(echo $archive_path | sed -e 's/diagout-//' -e 's/.tar.gz//') + rm -rf $archive_dir +fi %preun %systemd_preun @SERVICE_NAME@.service @@ -282,6 +303,30 @@ if [ -f "%{_sysconfdir}/prelink.conf" ]; then %{__sed} -i"" %{_sysconfdir}/prelink.conf -e "/\/opt\/td-agent\/bin\/ruby/d" fi fi +if [ $1 -eq 2 ]; then + # install missing plugins during upgrading package + if [ -f %{local_plugin_migration} ]; then + echo "Checking network connectivity..." + curl --fail --silent -O https://rubygems.org/specs.4.8.gz + if [ $? -eq 0 ]; then + echo "Install missing plugins automatically..." + /usr/sbin/fluent-gem list | grep fluent-plugin | cut -d' ' -f1 > %{local_base_plugins} + # NOTE: Do not install already bundled plugins + diff -u %{local_base_plugins} %{local_plugin_migration} | grep '^+fluent' | sed -e 's/\+//' > %{local_missing_plugins} + if [ -s %{local_missing_plugins} ]; then + cat %{local_missing_plugins} | xargs sudo /usr/sbin/fluent-gem install --no-document + else + echo "No need to install missing plugins..." + fi + rm -f %{local_base_plugins} + rm -f %{local_missing_plugins} + else + echo "Can't install missing plugins automatically, please install the following plugins manually." + cat %{local_plugin_migration} + fi + rm -f %{local_plugin_migration} + fi +fi %postun %systemd_postun_with_restart @SERVICE_NAME@.service From 7012e0bb55792825c06129b596e3b79b99c57338 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Tue, 15 Oct 2024 14:48:46 +0900 Subject: [PATCH 02/29] deb rpm: add auto/manual service restart during upgrading auto: Automatically restart service without downtime. service restart will be fired during %preun (upgrade). manual: Manually restart service by user. If user select manual, suppress auto-restart with automatically generated service hook %post and %systemd_postun_with_restart. when downgrading from v6, use manual and uninstall v6 then reinstall v5. Signed-off-by: Kentaro Hayashi --- fluent-package/debian/rules | 6 +++ .../templates/etc/systemd/fluentd.erb | 2 + .../fluent-package/deb/postinst | 10 ++++ .../package-scripts/fluent-package/deb/postrm | 20 ++++++++ .../package-scripts/fluent-package/deb/prerm | 50 +++++++++++++++++++ fluent-package/yum/fluent-package.spec.in | 44 ++++++++++++++-- 6 files changed, 129 insertions(+), 3 deletions(-) create mode 100755 fluent-package/templates/package-scripts/fluent-package/deb/prerm diff --git a/fluent-package/debian/rules b/fluent-package/debian/rules index 0b7a2352d..443c6c141 100755 --- a/fluent-package/debian/rules +++ b/fluent-package/debian/rules @@ -16,6 +16,12 @@ override_dh_auto_install: CI=$CI rake build:all FLUENT_PACKAGE_STAGING_PATH="$(CURDIR)/debian/tmp" PATH="$(HOME)/.cargo/bin:$(PATH)" dh_installman +# Suppress forcing service start/restart in postinst by omitting +# related start/restart hook script embedding. It does not omit +# deb-systemd-helper enable/update-state fluentd.service +override_dh_installsystemd: + dh_installsystemd --no-stop-on-upgrade + override_dh_auto_clean: rake clean dh_auto_clean diff --git a/fluent-package/templates/etc/systemd/fluentd.erb b/fluent-package/templates/etc/systemd/fluentd.erb index 1a0436121..01eff104b 100644 --- a/fluent-package/templates/etc/systemd/fluentd.erb +++ b/fluent-package/templates/etc/systemd/fluentd.erb @@ -1 +1,3 @@ FLUENT_PACKAGE_OPTIONS="" +# Control method to upgrade service (auto/manual) restart +FLUENT_PACKAGE_SERVICE_RESTART=auto diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postinst b/fluent-package/templates/package-scripts/fluent-package/deb/postinst index cc4e5c333..005684462 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postinst @@ -196,3 +196,13 @@ fi <% end %> #DEBHELPER# + +. /etc/default/<%= service_name %> +echo "FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" +case "$FLUENT_PACKAGE_SERVICE_RESTART" in + auto|manual) + echo "FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" + ;; + *) + ;; +esac diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postrm b/fluent-package/templates/package-scripts/fluent-package/deb/postrm index 24e237e04..8b59e5294 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postrm +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postrm @@ -78,3 +78,23 @@ case $1 in esac #DEBHELPER# + +pid=$(systemctl show <%= service_name %> --property=MainPID --value) +if [ $pid -ne 0 ]; then + env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ) + action=$(eval $env_vars && echo $FLUENT_PACKAGE_SERVICE_RESTART) + case "$action" in + auto) + if [ "$1" = "upgrade" ]; then + echo "Kick auto service upgrade mode to MainPID:$pid" + kill -USR2 $pid + fi + ;; + manual) + echo "No need to restart service in manual mode..." + ;; + *) + echo "Nothing to be done..." + ;; + esac +fi diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/prerm b/fluent-package/templates/package-scripts/fluent-package/deb/prerm new file mode 100755 index 000000000..37b6d9c49 --- /dev/null +++ b/fluent-package/templates/package-scripts/fluent-package/deb/prerm @@ -0,0 +1,50 @@ +#!/bin/sh +# prerm script for <%= service_name %>. +# +# See: dh_installdeb(1). + +set -e + +# Summary of how this script can be called: +# * 'remove' +# * 'upgrade' +# * 'failed-upgrade' +# * 'remove' 'in-favour' +# * 'deconfigure' 'in-favour' +# 'removing' +# +# for details, see https://www.debian.org/doc/debian-policy/ or +# the debian-policy package. + + +case "$1" in + remove|upgrade|deconfigure) + ;; + + failed-upgrade) + ;; + + *) + echo "prerm called with unknown argument '$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +. /etc/default/<%= service_name %> +if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "manual" ]; then + # Do not stop service because removing package will be executed + # for major downgrade (e.g. uninstall v6 then reinstall v5) + # In such a case, missing plugins for v5 cause trouble in + # restarting service. + # so instead of restarting service here, demand users to install + # such plugins in advance then delegate users to restart service + # manually later. + : +else + #DEBHELPER# +fi + +exit 0 diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index d1356f5d8..9e3826eed 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -209,10 +209,29 @@ if [ $1 -eq 2 ]; then fi %preun -%systemd_preun @SERVICE_NAME@.service +. %{_sysconfdir}/sysconfig/@SERVICE_NAME@ +echo "preun FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" +if [ $1 -eq 0 ]; then + if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "manual" ]; then + # When rollback to previous version, there is a case that user want to + # restart manually to reduce downtime. + : + else + # disable service here + %systemd_preun @SERVICE_NAME@.service + fi +fi %post -%systemd_post @SERVICE_NAME@.service +. %{_sysconfdir}/sysconfig/@SERVICE_NAME@ +echo "post FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" +if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "auto" ]; then + echo "Suppress auto restart in auto mode..." +elif [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "manual" ]; then + echo "Suppress auto restart in manual mode ..." +else + %systemd_post @SERVICE_NAME@.service +fi if [ $1 -eq 1 ]; then if [ -d /etc/@COMPAT_PACKAGE_DIR@ -a ! -h /etc/@COMPAT_PACKAGE_DIR@ ]; then touch %{v4migration} @@ -329,7 +348,26 @@ if [ $1 -eq 2 ]; then fi %postun -%systemd_postun_with_restart @SERVICE_NAME@.service +if [ $1 -eq 1 ]; then + # Control service during upgrading + . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ + echo "postun FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" + if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "auto" ]; then + pid=$(systemctl show fluentd --property=MainPID --value) + if [ $pid -gt 0 ]; then + echo "Kick auto service upgrade mode to MainPID:$pid" + kill -USR2 $pid + else + # no running fluentd service + echo "Suppress auto service upgrade mode to MainPID:$pid" + fi + elif [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "manual" ]; then + echo "No need to restart service in manual mode..." + else + # no support for upgrading without downtime + %systemd_postun_with_restart @SERVICE_NAME@.service + fi +fi if [ $1 -eq 0 ]; then # Uninstall # Without this uninstall conditional guard block ($1 -eq 0), symlink From 117e57f0e2e7e923737cbb0948d61bcc6c40c15e Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Fri, 18 Oct 2024 10:28:04 +0900 Subject: [PATCH 03/29] deb: remove debug print Accidentally debug print in preinst was pushed in 26785ce. Signed-off-by: Kentaro Hayashi --- .../templates/package-scripts/fluent-package/deb/preinst | 3 --- 1 file changed, 3 deletions(-) diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/preinst b/fluent-package/templates/package-scripts/fluent-package/deb/preinst index a4cf6b802..9a039afa0 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/preinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/preinst @@ -23,9 +23,6 @@ migrate_local_plugins() { fi } -echo "preinst v6: $1" -echo "preinst v6 prevver: $2" - case "$1" in upgrade) migrate_local_plugins From e85dda8ee8de4eceebe6a0411febe9305a53e8cd Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Fri, 18 Oct 2024 09:56:16 +0900 Subject: [PATCH 04/29] deb: fix wrong hook order to install plugins When upgrading package, the following hook is executed: plugins should be installed before restarting service. Before: * old prerm * new preinst collect plugin information * old postrm auto restart * new postinst install plugins After: * old prerm collect plugin information * new preinst * old postrm * new postinst install plugins and auto restart Signed-off-by: Kentaro Hayashi --- .../fluent-package/deb/postinst | 27 ++++++++++++++++++- .../package-scripts/fluent-package/deb/postrm | 19 ------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postinst b/fluent-package/templates/package-scripts/fluent-package/deb/postinst index 005684462..4b54a4576 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postinst @@ -171,6 +171,30 @@ install_missing_plugins() { fi } +fluentd_auto_restart() { + if [ -d /run/systemd/system ]; then + pid=$(systemctl show <%= service_name %> --property=MainPID --value) + if [ $pid -ne 0 ]; then + env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ) + action=$(eval $env_vars && echo $FLUENT_PACKAGE_SERVICE_RESTART) + case "$action" in + auto) + if [ "$1" = "upgrade" ]; then + echo "Kick auto service upgrade mode to MainPID:$pid" + kill -USR2 $pid + fi + ;; + manual) + echo "No need to restart service in manual mode..." + ;; + *) + echo "Nothing to be done..." + ;; + esac + fi + fi +} + case "$1" in configure) add_system_user @@ -179,7 +203,8 @@ case "$1" in fixperms migration_from_v4_post_process install_missing_plugins - ;; + fluentd_auto_restart + ;; abort-upgrade|abort-deconfigure|abort-remove) : ;; diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postrm b/fluent-package/templates/package-scripts/fluent-package/deb/postrm index 8b59e5294..c43e678b0 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postrm +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postrm @@ -79,22 +79,3 @@ esac #DEBHELPER# -pid=$(systemctl show <%= service_name %> --property=MainPID --value) -if [ $pid -ne 0 ]; then - env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ) - action=$(eval $env_vars && echo $FLUENT_PACKAGE_SERVICE_RESTART) - case "$action" in - auto) - if [ "$1" = "upgrade" ]; then - echo "Kick auto service upgrade mode to MainPID:$pid" - kill -USR2 $pid - fi - ;; - manual) - echo "No need to restart service in manual mode..." - ;; - *) - echo "Nothing to be done..." - ;; - esac -fi From 051a305671044640a8c4913887e1ef015e48a6c7 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Fri, 18 Oct 2024 16:13:16 +0900 Subject: [PATCH 05/29] deb: fix inconsistent phase comparison fluentd_auto_restart will be launched during "configure" phase, so there is no need to check that action. This is occurred by migrating restart logic from postrm to postinst. Signed-off-by: Kentaro Hayashi --- .../templates/package-scripts/fluent-package/deb/postinst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postinst b/fluent-package/templates/package-scripts/fluent-package/deb/postinst index 4b54a4576..aaee25483 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postinst @@ -179,10 +179,8 @@ fluentd_auto_restart() { action=$(eval $env_vars && echo $FLUENT_PACKAGE_SERVICE_RESTART) case "$action" in auto) - if [ "$1" = "upgrade" ]; then - echo "Kick auto service upgrade mode to MainPID:$pid" - kill -USR2 $pid - fi + echo "Kick auto service upgrade mode to MainPID:$pid" + kill -USR2 $pid ;; manual) echo "No need to restart service in manual mode..." From b99276b37b9185f2b9d097c732cfd875ff777725 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Wed, 23 Oct 2024 11:58:18 +0900 Subject: [PATCH 06/29] ci: fix tests for no-downtime Signed-off-by: Shizuo Fujita --- .../update-to-next-version-service-status.sh | 9 ++++++--- .../update-to-next-version-service-status.sh | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh b/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh index 502896283..8640ed872 100755 --- a/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh +++ b/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh @@ -55,10 +55,13 @@ else (! systemctl is-enabled fluentd) fi -if [ "$status_before_update" = active ] || [ "$enabled_before_update" = enabled ] ; then - # The service should restart automatically after update +if [ "$status_before_update" = active ]; then + # The service should NOT restart automatically after update + systemctl is-active fluentd + test $main_pid -eq $(systemctl show --value --property=MainPID fluentd) +elif [ "$enabled_before_update" = enabled ] && [ "$status_before_update" = inactive ]; then + # The service should start automatically systemctl is-active fluentd - test $main_pid -ne $(systemctl show --value --property=MainPID fluentd) else # The service should NOT start automatically (! systemctl is-active fluentd) diff --git a/fluent-package/yum/systemd-test/update-to-next-version-service-status.sh b/fluent-package/yum/systemd-test/update-to-next-version-service-status.sh index 845560e2c..dcdf9a978 100755 --- a/fluent-package/yum/systemd-test/update-to-next-version-service-status.sh +++ b/fluent-package/yum/systemd-test/update-to-next-version-service-status.sh @@ -65,9 +65,9 @@ else fi if [ "$status_before_update" = active ]; then - # The service should restart automatically after update + # The service should NOT restart automatically after update systemctl is-active fluentd - test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) else # The service should NOT start automatically (! systemctl is-active fluentd) From 0d71becb2dc6244fc1e90266686ff60d092e5e50 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Wed, 16 Oct 2024 17:51:29 +0900 Subject: [PATCH 07/29] rules: add --no-restart-after-upgrade option in dh_installsystemd for focal Signed-off-by: Shizuo Fujita --- fluent-package/debian/rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-package/debian/rules b/fluent-package/debian/rules index 443c6c141..7f918cd33 100755 --- a/fluent-package/debian/rules +++ b/fluent-package/debian/rules @@ -20,7 +20,7 @@ override_dh_auto_install: # related start/restart hook script embedding. It does not omit # deb-systemd-helper enable/update-state fluentd.service override_dh_installsystemd: - dh_installsystemd --no-stop-on-upgrade + dh_installsystemd --no-restart-after-upgrade --no-stop-on-upgrade override_dh_auto_clean: rake clean From 5b698f376bb376406d2649b059c7214890ce5fd1 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Thu, 24 Oct 2024 11:56:11 +0900 Subject: [PATCH 08/29] system-test: remove unnecessary condition Signed-off-by: Shizuo Fujita --- .../apt/systemd-test/update-to-next-version-service-status.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh b/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh index 8640ed872..b0dc1d5f2 100755 --- a/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh +++ b/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh @@ -59,7 +59,7 @@ if [ "$status_before_update" = active ]; then # The service should NOT restart automatically after update systemctl is-active fluentd test $main_pid -eq $(systemctl show --value --property=MainPID fluentd) -elif [ "$enabled_before_update" = enabled ] && [ "$status_before_update" = inactive ]; then +elif [ "$enabled_before_update" = enabled ]; then # The service should start automatically systemctl is-active fluentd else From 158d18fec50f0797199ee32c114ce17964e13503 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Thu, 24 Oct 2024 11:59:04 +0900 Subject: [PATCH 09/29] system-test: add comments Signed-off-by: Shizuo Fujita --- .../apt/systemd-test/update-to-next-version-service-status.sh | 1 + .../yum/systemd-test/update-to-next-version-service-status.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh b/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh index b0dc1d5f2..7b2031a56 100755 --- a/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh +++ b/fluent-package/apt/systemd-test/update-to-next-version-service-status.sh @@ -57,6 +57,7 @@ fi if [ "$status_before_update" = active ]; then # The service should NOT restart automatically after update + # (The process before update should continue to run) systemctl is-active fluentd test $main_pid -eq $(systemctl show --value --property=MainPID fluentd) elif [ "$enabled_before_update" = enabled ]; then diff --git a/fluent-package/yum/systemd-test/update-to-next-version-service-status.sh b/fluent-package/yum/systemd-test/update-to-next-version-service-status.sh index dcdf9a978..48bd7b7c8 100755 --- a/fluent-package/yum/systemd-test/update-to-next-version-service-status.sh +++ b/fluent-package/yum/systemd-test/update-to-next-version-service-status.sh @@ -66,6 +66,7 @@ fi if [ "$status_before_update" = active ]; then # The service should NOT restart automatically after update + # (The process before update should continue to run) systemctl is-active fluentd test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) else From c0ce192818e5a54322efd5032027bc57871bd1c3 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Wed, 30 Oct 2024 11:08:04 +0900 Subject: [PATCH 10/29] ci: extend timeout for v6 workflow (#701) To verify major upgrade in workflow, it needs more package build time. Signed-off-by: Kentaro Hayashi --- .github/workflows/apt.yml | 2 +- .github/workflows/yum.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index e25e68b8f..f502b41a4 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -11,7 +11,7 @@ concurrency: jobs: build: name: Build - timeout-minutes: 60 + timeout-minutes: 120 strategy: fail-fast: false matrix: diff --git a/.github/workflows/yum.yml b/.github/workflows/yum.yml index 301bca49e..9cf2b7cfc 100644 --- a/.github/workflows/yum.yml +++ b/.github/workflows/yum.yml @@ -11,7 +11,7 @@ concurrency: jobs: build: name: Build - timeout-minutes: 60 + timeout-minutes: 120 strategy: fail-fast: false matrix: From 273c18014b441d7a0655e174b188d7671800c82a Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Wed, 30 Oct 2024 17:15:43 +0900 Subject: [PATCH 11/29] ci: show debug message to investigate Signed-off-by: Kentaro Hayashi --- .github/workflows/apt.yml | 18 ++++++++++++++++++ fluent-package/apt/systemd-test/test.sh | 2 +- fluent-package/yum/systemd-test/test.sh | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index f502b41a4..54f7a5dc7 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -203,5 +203,23 @@ jobs: with: name: packages-apt-source-${{ matrix.rake-job }} - uses: canonical/setup-lxd@v0.1.2 + - name: Run diagnostic + run: | + uname -a + echo "::group::snap info lxd" + snap info lxd + echo "::endgroup::" + echo "::group::snap services lxd" + snap services lxd + echo "::endgroup::" + echo "::group::snap logs lxd" + sudo snap logs lxd + echo "::endgroup::" + echo "::group::lxc remote list" + lxc remote list + echo "::endgroup::" + echo "::group::lxc list images:" + lxc image list images: + echo "::endgroup::" - name: Run Test ${{ matrix.test }} on ${{ matrix.lxc-image }} run: fluent-package/apt/systemd-test/test.sh ${{ matrix.lxc-image }} ${{ matrix.test }} diff --git a/fluent-package/apt/systemd-test/test.sh b/fluent-package/apt/systemd-test/test.sh index 45469953b..b91e456af 100755 --- a/fluent-package/apt/systemd-test/test.sh +++ b/fluent-package/apt/systemd-test/test.sh @@ -15,7 +15,7 @@ dir="/host/fluent-package/apt/systemd-test" set -eux echo "::group::Run test: launch $image" -lxc launch $image target +lxc launch $image target --debug sleep 5 echo "::endgroup::" echo "::group::Run test: configure $image" diff --git a/fluent-package/yum/systemd-test/test.sh b/fluent-package/yum/systemd-test/test.sh index 4a4d58120..4c73e2c30 100755 --- a/fluent-package/yum/systemd-test/test.sh +++ b/fluent-package/yum/systemd-test/test.sh @@ -15,7 +15,7 @@ dir="/host/fluent-package/yum/systemd-test" set -eux echo "::group::Run test: launch $image" -lxc launch $image target +lxc launch $image target --debug sleep 5 echo "::endgroup::" echo "::group::Run test: configure $image" From dcd91ce04035cc4e24ac3590d1ca12f4be68bfe2 Mon Sep 17 00:00:00 2001 From: Watson Date: Thu, 31 Oct 2024 17:51:43 +0900 Subject: [PATCH 12/29] ci: add test to update without data lost (#699) This PR adds testing to ensure that package upgrades succeed without data loss. At present, the following plugins will be checked: - in_tcp - in_udp - in_syslog Signed-off-by: Shizuo Fujita Signed-off-by: Daijiro Fukuda --- .github/workflows/apt.yml | 1 + .github/workflows/yum.yml | 2 + ...pdate-to-next-version-without-data-lost.sh | 49 ++++++++++++ fluent-package/test-tools/fluentd.conf | 72 ++++++++++++++++++ fluent-package/test-tools/logdata-sender.rb | 74 ++++++++++++++++++ fluent-package/test-tools/rsyslog.conf | 1 + ...pdate-to-next-version-without-data-lost.sh | 75 +++++++++++++++++++ 7 files changed, 274 insertions(+) create mode 100755 fluent-package/apt/systemd-test/update-to-next-version-without-data-lost.sh create mode 100644 fluent-package/test-tools/fluentd.conf create mode 100644 fluent-package/test-tools/logdata-sender.rb create mode 100644 fluent-package/test-tools/rsyslog.conf create mode 100755 fluent-package/yum/systemd-test/update-to-next-version-without-data-lost.sh diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index 54f7a5dc7..371687b9f 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -157,6 +157,7 @@ jobs: - "update-to-next-version-service-status.sh enabled inactive" - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" + - "update-to-next-version-without-data-lost.sh" include: - label: Debian bullseye amd64 rake-job: debian-bullseye diff --git a/.github/workflows/yum.yml b/.github/workflows/yum.yml index 9cf2b7cfc..c73e79dbb 100644 --- a/.github/workflows/yum.yml +++ b/.github/workflows/yum.yml @@ -131,6 +131,7 @@ jobs: - "update-to-next-version-service-status.sh enabled inactive" - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" + - "update-to-next-version-without-data-lost.sh" include: - label: AmazonLinux 2 x86_64 rake-job: amazonlinux-2 @@ -195,6 +196,7 @@ jobs: - "update-to-next-version-service-status.sh enabled inactive" - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" + - "update-to-next-version-without-data-lost.sh" include: - label: RockyLinux 8 x86_64 rake-job: rockylinux-8 diff --git a/fluent-package/apt/systemd-test/update-to-next-version-without-data-lost.sh b/fluent-package/apt/systemd-test/update-to-next-version-without-data-lost.sh new file mode 100755 index 000000000..9f6c5688f --- /dev/null +++ b/fluent-package/apt/systemd-test/update-to-next-version-without-data-lost.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/../commonvar.sh + +sudo apt install -V -y rsyslog + +# Install the current +sudo apt install -V -y \ + /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +# Make a dummy pacakge for the next version +dpkg-deb -R /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb tmp +last_ver=$(cat tmp/DEBIAN/control | grep "Version: " | sed -E "s/Version: ([0-9.]+)-([0-9]+)/\2/g") +sed -i -E "s/Version: ([0-9.]+)-([0-9]+)/Version: \1-$(($last_ver+1))/g" tmp/DEBIAN/control +dpkg-deb --build tmp next_version.deb + +# Set up configuration +cat < $(dirname $0)/../../test-tools/rsyslog.conf >> /etc/rsyslog.conf +cp $(dirname $0)/../../test-tools/fluentd.conf /etc/fluent/fluentd.conf + +# Launch rsyslog +sudo systemctl restart rsyslog + +# Launch fluentd +sudo systemctl restart fluentd +main_pid=$(systemctl show --value --property=MainPID fluentd) + +# Ensure to wait for fluentd launching +sleep 1 + +# Send logs in background for 4 seconds +/opt/fluent/bin/ruby $(dirname $0)/../../test-tools/logdata-sender.rb \ + --udp-data-count 50 --tcp-data-count 60 --syslog-data-count 70 --syslog-identifer "test-syslog" --duration 4 & + +sleep 1 + +# Update to the next version +sudo apt install -V -y ./next_version.deb +test $main_pid -eq $(systemctl show --value --property=MainPID fluentd) + +sleep 3 + +# Stop fluentd to flush the logs and check +systemctl stop fluentd +test $(wc -l /var/log/fluent/test_udp*.log | cut -d' ' -f 1) = "50" +test $(wc -l /var/log/fluent/test_tcp*.log | cut -d' ' -f 1) = "60" +test $(grep "test-syslog" /var/log/fluent/test_syslog*.log | wc -l) = "70" diff --git a/fluent-package/test-tools/fluentd.conf b/fluent-package/test-tools/fluentd.conf new file mode 100644 index 000000000..cdfc38423 --- /dev/null +++ b/fluent-package/test-tools/fluentd.conf @@ -0,0 +1,72 @@ + + @type udp + tag test_udp + + port 5170 + bind 0.0.0.0 + + + @type none + + + + + @type tcp + tag test_tcp + + port 5170 + bind 0.0.0.0 + + + @type none + + + + + @type syslog + port 5140 + bind 0.0.0.0 + tag test_syslog + + + + @type file + path /var/log/fluent/test_udp + + + @type file + path /var/log/fluent/test_udp-buffer + flush_method interval + flush_mode interval + flush_interval 10 + flush_at_shutdown true + + + + + @type file + path /var/log/fluent/test_tcp + + + @type file + path /var/log/fluent/test_tcp-buffer + flush_method interval + flush_mode interval + flush_interval 10 + flush_at_shutdown true + + + + + @type file + path /var/log/fluent/test_syslog + + + @type file + path /var/log/fluent/test_syslog-buffer + flush_method interval + flush_mode interval + flush_interval 10 + flush_at_shutdown true + + diff --git a/fluent-package/test-tools/logdata-sender.rb b/fluent-package/test-tools/logdata-sender.rb new file mode 100644 index 000000000..cd79c0ad3 --- /dev/null +++ b/fluent-package/test-tools/logdata-sender.rb @@ -0,0 +1,74 @@ +require "socket" +require "syslog" +require "optparse" + +udp_data_count = 50 +tcp_data_count = 60 +syslog_data_count = 70 +syslog_identifer = "test-syslog" +output_duration_sec = 4.0 + +opt = OptionParser.new +opt.on("--udp-data-count num") { |v| udp_data_count = v.to_i } +opt.on("--tcp-data-count num") { |v| tcp_data_count = v.to_i } +opt.on("--syslog-data-count num") { |v| syslog_data_count = v.to_i } +opt.on("--syslog-identifer name") { |v| syslog_identifer = v } +opt.on("--duration num") { |v| output_duration_sec = v.to_f } +opt.parse!(ARGV) + +threads = [] + +## UDP +threads << Thread.new do + i = 0 + begin + s = UDPSocket.open + s.connect("localhost", 5170) + + loop do + break if i == udp_data_count + s.puts "[udp][#{i}] hello" + i += 1 + sleep (output_duration_sec / udp_data_count) + end + rescue Errno::ECONNRESET, Errno::ECONNREFUSED + retry + end +ensure + s.close +end + +## TCP +threads << Thread.new do + i = 0 + begin + s = TCPSocket.open("localhost", 5170) + + loop do + break if i == tcp_data_count + s.puts "[tcp][#{i}] hello" + i += 1 + sleep (output_duration_sec / tcp_data_count) + end + rescue Errno::ECONNRESET, Errno::ECONNREFUSED + retry + end +ensure + s.close +end + +## Syslog +threads << Thread.new do + Syslog.open(syslog_identifer) + i = 0 + loop do + break if i == syslog_data_count + Syslog.info("[syslog][#{i}] hello") + i += 1 + sleep (output_duration_sec / syslog_data_count) + end +ensure + Syslog.close +end + +threads.each(&:join) diff --git a/fluent-package/test-tools/rsyslog.conf b/fluent-package/test-tools/rsyslog.conf new file mode 100644 index 000000000..e74a06ae6 --- /dev/null +++ b/fluent-package/test-tools/rsyslog.conf @@ -0,0 +1 @@ +user.* @127.0.0.1:5140 diff --git a/fluent-package/yum/systemd-test/update-to-next-version-without-data-lost.sh b/fluent-package/yum/systemd-test/update-to-next-version-without-data-lost.sh new file mode 100755 index 000000000..7ed39730a --- /dev/null +++ b/fluent-package/yum/systemd-test/update-to-next-version-without-data-lost.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/commonvar.sh + +sudo $DNF install -y rsyslog + +# Install the current +package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm" +sudo $DNF install -y $package + +# Make a dummy pacakge for the next version +case $distribution in + amazon) + case $version in + 2023) + curl -L -o rpmrebuild.noarch.rpm https://sourceforge.net/projects/rpmrebuild/files/latest/download + sudo $DNF install -y ./rpmrebuild.noarch.rpm + ;; + 2) + sudo amazon-linux-extras install -y epel + sudo $DNF install -y rpmrebuild + ;; + esac + ;; + *) + sudo $DNF install -y epel-release + sudo $DNF install -y rpmrebuild + ;; +esac + +# Example: "1.el9" +release=$(rpmquery --queryformat="%{Release}" -p $package) +# Example: "1" +release_ver=$(echo $release | cut -d . -f1) +# Example: "2.el9" +next_release=$(($release_ver+1)).$(echo $release | cut -d. -f2) +rpmrebuild --release=$next_release --modify="find $HOME -name fluentd.service | xargs sed -i -E 's/FLUENT_PACKAGE_VERSION=([0-9.]+)/FLUENT_PACKAGE_VERSION=\1.1/g'" --package $package +next_package=$(find rpmbuild -name "*.rpm") +rpm2cpio $next_package | cpio -id ./usr/lib/systemd/system/fluentd.service +next_package_ver=$(cat ./usr/lib/systemd/system/fluentd.service | grep "FLUENT_PACKAGE_VERSION" | sed -E "s/Environment=FLUENT_PACKAGE_VERSION=(.+)/\1/") +echo "repacked next fluent-package version: $next_package_ver" + +# Set up configuration +cat < $(dirname $0)/../../test-tools/rsyslog.conf >> /etc/rsyslog.conf +cp $(dirname $0)/../../test-tools/fluentd.conf /etc/fluent/fluentd.conf + +# Launch rsyslog +sudo systemctl restart rsyslog + +# Launch fluentd +sudo systemctl enable --now fluentd +main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Ensure to wait for fluentd launching +sleep 1 + +# Send logs in background for 4 seconds +/opt/fluent/bin/ruby $(dirname $0)/../../test-tools/logdata-sender.rb \ + --udp-data-count 50 --tcp-data-count 60 --syslog-data-count 70 --syslog-identifer "test-syslog" --duration 4 & + +sleep 1 + +# Update to the next version +sudo $DNF install -y ./$next_package +test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +sleep 3 + +# Stop fluentd to flush the logs and check +systemctl stop fluentd +test $(wc -l /var/log/fluent/test_udp*.log | cut -d' ' -f 1) = "50" +test $(wc -l /var/log/fluent/test_tcp*.log | cut -d' ' -f 1) = "60" +test $(grep "test-syslog" /var/log/fluent/test_syslog*.log | wc -l) = "70" From 656436db00a36c87798b16c10349e21bd1ccbafb Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Fri, 1 Nov 2024 14:02:30 +0900 Subject: [PATCH 13/29] deb rpm: fix local dependency gem (#688) Before: * missing fluent-plugin was installed After: * missing fluent-plugin was installed * missing dependency gem was also installed NOTE: * if missing gem requires development packages to build it, it will fail. * fluent-diagtool depends on highly systemd service, so it is simple just to use fluent-gem detecting missing gems. --------- Signed-off-by: Kentaro Hayashi --- .github/workflows/apt.yml | 23 +++++++ .github/workflows/yum.yml | 31 ++++++++- .../update-to-next-major-version.sh | 22 +++++++ fluent-package/bump-version-v6.patch | 65 +++++++++++++++++++ .../fluent-package/deb/postinst | 41 ++++++------ .../fluent-package/deb/preinst | 16 ++--- fluent-package/yum/fluent-package.spec.in | 57 ++++++---------- .../update-to-next-major-version.sh | 22 +++++++ 8 files changed, 208 insertions(+), 69 deletions(-) create mode 100755 fluent-package/apt/systemd-test/update-to-next-major-version.sh create mode 100644 fluent-package/bump-version-v6.patch create mode 100755 fluent-package/yum/systemd-test/update-to-next-major-version.sh diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index 371687b9f..6eea16033 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -54,16 +54,34 @@ jobs: fluent-package/apt/repositories fluent-apt-source/apt/repositories fluent-lts-apt-source/apt/repositories + v6-test/fluent-package/apt/repositories key: ${{ runner.os }}-cache-${{ matrix.rake-job }}-${{ hashFiles('**/config.rb', '**/Rakefile', '**/Gemfile*', 'fluent-package/templates/**', 'fluent-package/debian/**', 'fluent-package/apt/**/Dockerfile') }} - name: Build deb with Docker if: ${{ ! steps.cache-deb.outputs.cache-hit }} run: | rake apt:build APT_TARGETS=${{ matrix.rake-job }} + - uses: actions/checkout@master + if: ${{ ! steps.cache-deb.outputs.cache-hit }} + with: + path: v6-test + - name: Build v6 deb with Docker + if: ${{ ! steps.cache-deb.outputs.cache-hit }} + run: | + cd v6-test + git config user.email "fluentd@googlegroups.com" + git config user.name "Fluentd developers" + git am fluent-package/bump-version-v6.patch + rake apt:build APT_TARGETS=${{ matrix.rake-job }} - name: Upload fluent-package deb uses: actions/upload-artifact@master with: name: packages-${{ matrix.rake-job }} path: fluent-package/apt/repositories + - name: Upload v6 fluent-package deb + uses: actions/upload-artifact@master + with: + name: v6-packages-${{ matrix.rake-job }} + path: v6-test/fluent-package/apt/repositories - name: Upload fluent-apt-source deb uses: actions/upload-artifact@master with: @@ -158,6 +176,7 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-without-data-lost.sh" + - "update-to-next-major-version.sh" include: - label: Debian bullseye amd64 rake-job: debian-bullseye @@ -200,6 +219,10 @@ jobs: - uses: actions/download-artifact@v4 with: name: packages-${{ matrix.rake-job }} + - uses: actions/download-artifact@v4 + with: + name: v6-packages-${{ matrix.rake-job }} + path: v6-test - uses: actions/download-artifact@v4 with: name: packages-apt-source-${{ matrix.rake-job }} diff --git a/.github/workflows/yum.yml b/.github/workflows/yum.yml index c73e79dbb..9f2341def 100644 --- a/.github/workflows/yum.yml +++ b/.github/workflows/yum.yml @@ -50,17 +50,36 @@ jobs: uses: actions/cache@v4 id: cache-rpm with: - path: fluent-package/yum/repositories + path: | + fluent-package/yum/repositories + v6-test/fluent-package/yum/repositories key: ${{ runner.os }}-cache-${{ matrix.rake-job }}-${{ hashFiles('**/config.rb', '**/Rakefile', '**/Gemfile*', '**/*.spec.in', 'fluent-package/templates/**', 'fluent-package/yum/**/Dockerfile') }} - name: Build rpm with Docker if: ${{ ! steps.cache-rpm.outputs.cache-hit }} run: | rake yum:build YUM_TARGETS=${{ matrix.rake-job }} + - uses: actions/checkout@master + if: ${{ ! steps.cache-rpm.outputs.cache-hit }} + with: + path: v6-test + - name: Build v6 rpm with Docker + if: ${{ ! steps.cache-rpm.outputs.cache-hit }} + run: | + cd v6-test + git config user.email "fluentd@googlegroups.com" + git config user.name "Fluentd developers" + git am fluent-package/bump-version-v6.patch + rake yum:build YUM_TARGETS=${{ matrix.rake-job }} - name: Upload fluent-package rpm uses: actions/upload-artifact@v4 with: name: packages-${{ matrix.rake-job }} path: fluent-package/yum/repositories + - name: Upload v6 fluent-package rpm + uses: actions/upload-artifact@v4 + with: + name: v6-packages-${{ matrix.rake-job }} + path: v6-test/fluent-package/yum/repositories # TODO move the following steps to "Test" job - name: Check Package Size run: | @@ -132,6 +151,7 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-without-data-lost.sh" + - "update-to-next-major-version.sh" include: - label: AmazonLinux 2 x86_64 rake-job: amazonlinux-2 @@ -151,6 +171,10 @@ jobs: - uses: actions/download-artifact@v4 with: name: packages-${{ matrix.rake-job }} + - uses: actions/download-artifact@v4 + with: + name: v6-packages-${{ matrix.rake-job }} + path: v6-test - uses: canonical/setup-lxd@v0.1.2 - name: Run diagnostic run: | @@ -197,6 +221,7 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-without-data-lost.sh" + - "update-to-next-major-version.sh" include: - label: RockyLinux 8 x86_64 rake-job: rockylinux-8 @@ -209,6 +234,10 @@ jobs: - uses: actions/download-artifact@v4 with: name: packages-${{ matrix.rake-job }} + - uses: actions/download-artifact@v4 + with: + name: v6-packages-${{ matrix.rake-job }} + path: v6-test - uses: canonical/setup-lxd@v0.1.2 - name: Run Test ${{ matrix.test }} on ${{ matrix.lxc-image }} run: fluent-package/yum/systemd-test/test.sh ${{ matrix.lxc-image }} ${{ matrix.test }} diff --git a/fluent-package/apt/systemd-test/update-to-next-major-version.sh b/fluent-package/apt/systemd-test/update-to-next-major-version.sh new file mode 100755 index 000000000..d4542c486 --- /dev/null +++ b/fluent-package/apt/systemd-test/update-to-next-major-version.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/../commonvar.sh + +# Install the current +sudo apt install -V -y \ + /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +# Install plugin manually (plugin and gem) +sudo /opt/fluent/bin/fluent-gem install --no-document fluent-plugin-concat +sudo /opt/fluent/bin/fluent-gem install --no-document gqtp + +# Install next major version +sudo apt install -V -y \ + /host/v6-test/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +# Test: Check whether plugin/gem were installed during upgrading +/opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat +# Non fluent-plugin- prefix gem should not be installed automatically +(! /opt/fluent/bin/fluent-gem list | grep gqtp) diff --git a/fluent-package/bump-version-v6.patch b/fluent-package/bump-version-v6.patch new file mode 100644 index 000000000..dfa68a27b --- /dev/null +++ b/fluent-package/bump-version-v6.patch @@ -0,0 +1,65 @@ +From 887c36b60822995aa889fea6a181f00975cdfff7 Mon Sep 17 00:00:00 2001 +From: Kentaro Hayashi +Date: Thu, 17 Oct 2024 19:45:02 +0900 +Subject: [PATCH 1/2] bump version + +Signed-off-by: Kentaro Hayashi +--- + fluent-package/config.rb | 6 +++--- + fluent-package/debian/changelog | 6 ++++++ + fluent-package/yum/fluent-package.spec.in | 3 +++ + 3 files changed, 12 insertions(+), 3 deletions(-) + +diff --git a/fluent-package/config.rb b/fluent-package/config.rb +index a9e13bc..e61bca4 100644 +--- a/fluent-package/config.rb ++++ b/fluent-package/config.rb +@@ -1,5 +1,5 @@ + PACKAGE_NAME = "fluent-package" +-PACKAGE_VERSION = "5.1.0" ++PACKAGE_VERSION = "6.0.0" + + # Keep internal path (/opt/td-agent) for package name migration + SERVICE_NAME = "fluentd" +@@ -23,8 +23,8 @@ OPENSSL_FOR_MACOS_SHA256SUM = "6c13d2bf38fdf31eac3ce2a347073673f5d63263398f1f69d + BUNDLER_VERSION= "2.3.27" + + # https://www.ruby-lang.org/en/downloads/ (tar.gz) +-BUNDLED_RUBY_VERSION = "3.2.5" +-BUNDLED_RUBY_SOURCE_SHA256SUM = "ef0610b498f60fb5cfd77b51adb3c10f4ca8ed9a17cb87c61e5bea314ac34a16" ++BUNDLED_RUBY_VERSION = "3.3.5" ++BUNDLED_RUBY_SOURCE_SHA256SUM = "3781a3504222c2f26cb4b9eb9c1a12dbf4944d366ce24a9ff8cf99ecbce75196" + + BUNDLED_RUBY_PATCHES = [ + # An example entry: +diff --git a/fluent-package/debian/changelog b/fluent-package/debian/changelog +index f24ec3e..0089f56 100644 +--- a/fluent-package/debian/changelog ++++ b/fluent-package/debian/changelog +@@ -1,3 +1,9 @@ ++fluent-package (6.0.0-1) unstable; urgency=low ++ ++ * New upstream release. ++ ++ -- Kentaro Hayashi Tue, 8 Oct 2024 07:47:29 -0000 ++ + fluent-package (5.1.0-1) unstable; urgency=low + + * New upstream release. +diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in +index 4833f8e..da9da8c 100644 +--- a/fluent-package/yum/fluent-package.spec.in ++++ b/fluent-package/yum/fluent-package.spec.in +@@ -478,6 +478,9 @@ fi + # NOTE: %{_tmpfilesdir} is available since CentOS 7 + %attr(0755,fluentd,fluentd) %dir /tmp/@PACKAGE_DIR@ + %changelog ++* Mon Oct 7 2024 Kentaro Hayashi - 6.0.0-1 ++- New upstream release. (Dummy) ++ + * Mon Jul 29 2024 Kentaro Hayashi - 5.1.0-1 + - New upstream release. + +-- +2.45.2 + diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postinst b/fluent-package/templates/package-scripts/fluent-package/deb/postinst index aaee25483..679264d99 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postinst @@ -145,29 +145,26 @@ migration_from_v4_post_process() { fi } -local_plugin_migration=/tmp/<%= package_dir %>/.local_plugin_migration local_base_plugins=/tmp/<%= package_dir %>/.local_base_plugins -local_missing_plugins=/tmp/<%= package_dir %>/.local_missing_plugins install_missing_plugins() { - if [ -f $local_plugin_migration ]; then - echo "Checking network connectivity..." - if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then - echo "Can't install missing plugins automatically, please install the following plugins manually." - cat $local_plugin_migration - else - echo "Install missing plugins automatically..." - /usr/sbin/fluent-gem list | grep fluent-plugin | cut -d' ' -f1 > $local_base_plugins - # NOTE: Do not install already bundled plugins - diff -u $local_base_plugins $local_plugin_migration | grep '^+fluent' | sed -e 's/\+//' > $local_missing_plugins - if [ -s $local_missing_plugins ]; then - cat $local_missing_plugins | xargs sudo /usr/sbin/fluent-gem install --no-document - else - echo "No need to install missing plugins..." - fi - rm -f $local_base_plugins - rm -f $local_missing_plugins - fi - rm -f $local_plugin_migration + # Install missing gems (even though systemd is not available, it works) + if [ -f $local_base_plugins ]; then + local_current_plugins=$(/usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose) + if ! grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" $local_base_plugins; then + echo "No missing plugins to install" + else + if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then + echo "No network connectivity..." + else + grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" $local_base_plugins | while read missing_gem + do + if ! /usr/sbin/fluent-gem install --no-document $missing_gem; then + echo "Can't install missing plugin automatically: please install $missing_gem manually." + fi + done + fi + fi + rm -f $local_base_plugins fi } @@ -175,7 +172,7 @@ fluentd_auto_restart() { if [ -d /run/systemd/system ]; then pid=$(systemctl show <%= service_name %> --property=MainPID --value) if [ $pid -ne 0 ]; then - env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ) + env_vars=$(sed -e 's/\x0/\n/g' /proc/$pid/environ) action=$(eval $env_vars && echo $FLUENT_PACKAGE_SERVICE_RESTART) case "$action" in auto) diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/preinst b/fluent-package/templates/package-scripts/fluent-package/deb/preinst index 9a039afa0..c01612591 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/preinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/preinst @@ -10,17 +10,15 @@ set -e # for details, see https://www.debian.org/doc/debian-policy/ or # the debian-policy package. -local_plugin_migration=/tmp/<%= package_dir %>/.local_plugin_migration +local_base_plugins=/tmp/<%= package_dir %>/.local_base_plugins migrate_local_plugins() { - # collect manually installed plugins - archive_path=$(sudo /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp | tail -n 1 | cut -d' ' -f10) - local_gem_output=$(echo $archive_path | sed -e 's/diagout-//' -e 's/.tar.gz//')/output/gem_local_list.output - if [ -f $local_gem_output ]; then - if [ -s $local_gem_output ]; then - # If there are missing plugins, mark path to it - cp $local_gem_output $local_plugin_migration - fi + if [ ! -d /run/systemd/system ]; then + # tmpfiles.d owns /tmp/<%= package_dir %>, but not created without systemd + mkdir -p /tmp/<%= package_dir %> fi + # collect list of gems + # We don't use fluent-diagtool here because it depends on systemd and piuparts fails + /opt/fluent/bin/fluent-gem list '^fluent-plugin-' --no-version --no-verbose > $local_base_plugins } case "$1" in diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index 9e3826eed..18761e0c1 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -32,8 +32,7 @@ %define v4migration_with_restart /tmp/@PACKAGE_DIR@/.v4migration_with_restart %define v4migration_old_rotate_config_saved /tmp/@PACKAGE_DIR@/.old_rotate_config %define v4migration_enabled_service /tmp/@PACKAGE_DIR@/.v4migration_enabled_service -%define local_plugin_migration /tmp/@PACKAGE_DIR@/.local_plugin_migration -%define local_base_plugins /tmp/@PACKAGE_DIR@/.base-plugins +%define local_base_plugins /tmp/@PACKAGE_DIR@/.local_base_plugins # Omit the brp-python-bytecompile automagic because post hook for ffi fails on AmazonLinux 2. %if %{_amazon_ver} == 2 @@ -189,23 +188,8 @@ else fi fi if [ $1 -eq 2 ]; then - # collect manually installed plugins during upgrading - archive_path=$(sudo /opt/fluent/bin/fluent-diagtool -t fluentd -o /tmp | tail -n 1 | cut -d' ' -f10) - local_gem_output=$(echo $archive_path | sed -e 's/diagout-//' -e 's/.tar.gz//')/output/gem_local_list.output - if [ -f $local_gem_output ]; then - if [ -s $local_gem_output ]; then - # If there are missing plugins, mark path to it - echo "Detected missing plugins..." - cp $local_gem_output %{local_plugin_migration} - else - echo "Missing $local_gem_output" - fi - else - echo "Missing $local_gem_output to check locally installed plugins." - fi - rm -f $archive_path - archive_dir=$(echo $archive_path | sed -e 's/diagout-//' -e 's/.tar.gz//') - rm -rf $archive_dir + # collect installed gems during upgrading + /opt/fluent/bin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose > %{local_base_plugins} fi %preun @@ -324,26 +308,23 @@ if [ -f "%{_sysconfdir}/prelink.conf" ]; then fi if [ $1 -eq 2 ]; then # install missing plugins during upgrading package - if [ -f %{local_plugin_migration} ]; then - echo "Checking network connectivity..." - curl --fail --silent -O https://rubygems.org/specs.4.8.gz - if [ $? -eq 0 ]; then - echo "Install missing plugins automatically..." - /usr/sbin/fluent-gem list | grep fluent-plugin | cut -d' ' -f1 > %{local_base_plugins} - # NOTE: Do not install already bundled plugins - diff -u %{local_base_plugins} %{local_plugin_migration} | grep '^+fluent' | sed -e 's/\+//' > %{local_missing_plugins} - if [ -s %{local_missing_plugins} ]; then - cat %{local_missing_plugins} | xargs sudo /usr/sbin/fluent-gem install --no-document + if [ -f %{local_base_plugins} ]; then + local_current_plugins=$(/usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose) + if ! grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins}; then + echo "No missing plugins to install" + else + if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then + echo "No network connectivity..." else - echo "No need to install missing plugins..." + grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins} | while read missing_gem + do + if ! /usr/sbin/fluent-gem install --no-document $missing_gem; then + echo "Can't install missing plugin automatically: please install $missing_gem manually." + fi + done fi - rm -f %{local_base_plugins} - rm -f %{local_missing_plugins} - else - echo "Can't install missing plugins automatically, please install the following plugins manually." - cat %{local_plugin_migration} fi - rm -f %{local_plugin_migration} + rm -f %{local_base_plugins} fi fi @@ -353,7 +334,9 @@ if [ $1 -eq 1 ]; then . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ echo "postun FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "auto" ]; then - pid=$(systemctl show fluentd --property=MainPID --value) + # systemctl ... --property=MainPID --value is available since systemd 230 or later. + # thus for amazonlinux:2, it can not be used. + pid=$(systemctl show fluentd --property=MainPID | cut -d'=' -f2) if [ $pid -gt 0 ]; then echo "Kick auto service upgrade mode to MainPID:$pid" kill -USR2 $pid diff --git a/fluent-package/yum/systemd-test/update-to-next-major-version.sh b/fluent-package/yum/systemd-test/update-to-next-major-version.sh new file mode 100755 index 000000000..ff88f70ad --- /dev/null +++ b/fluent-package/yum/systemd-test/update-to-next-major-version.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/commonvar.sh + +# Install the current +package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-*.rpm" +sudo $DNF install -y $package + +# Install plugin manually (plugin and gem) +sudo /opt/fluent/bin/fluent-gem install --no-document fluent-plugin-concat +sudo /opt/fluent/bin/fluent-gem install --no-document gqtp + +# Install next major version +package="/host/v6-test/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-*.rpm" +sudo $DNF install -y $package + +# Test: Check whether plugin/gem were installed during upgrading +/opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat +# Non fluent-plugin- prefix gem should not be installed automatically +(! /opt/fluent/bin/fluent-gem list | grep gqtp) From ca9059e1fc0f4acf6d57bf51ee2d663a7d311b95 Mon Sep 17 00:00:00 2001 From: Watson Date: Tue, 5 Nov 2024 10:44:56 +0900 Subject: [PATCH 14/29] ci: add test to update with auto / manual feature (#712) add test to update with auto / manual feature. Signed-off-by: Shizuo Fujita Signed-off-by: Daijiro Fukuda --- .github/workflows/apt.yml | 1 + .github/workflows/yum.yml | 2 + ...te-to-next-version-with-auto-and-manual.sh | 46 ++++++++++++ ...te-to-next-version-with-auto-and-manual.sh | 74 +++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100755 fluent-package/apt/systemd-test/update-to-next-version-with-auto-and-manual.sh create mode 100755 fluent-package/yum/systemd-test/update-to-next-version-with-auto-and-manual.sh diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index 6eea16033..c446b2457 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -176,6 +176,7 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-without-data-lost.sh" + - "update-to-next-version-with-auto-and-manual.sh" - "update-to-next-major-version.sh" include: - label: Debian bullseye amd64 diff --git a/.github/workflows/yum.yml b/.github/workflows/yum.yml index 9f2341def..f3b0a97a7 100644 --- a/.github/workflows/yum.yml +++ b/.github/workflows/yum.yml @@ -151,6 +151,7 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-without-data-lost.sh" + - "update-to-next-version-with-auto-and-manual.sh" - "update-to-next-major-version.sh" include: - label: AmazonLinux 2 x86_64 @@ -221,6 +222,7 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-without-data-lost.sh" + - "update-to-next-version-with-auto-and-manual.sh" - "update-to-next-major-version.sh" include: - label: RockyLinux 8 x86_64 diff --git a/fluent-package/apt/systemd-test/update-to-next-version-with-auto-and-manual.sh b/fluent-package/apt/systemd-test/update-to-next-version-with-auto-and-manual.sh new file mode 100755 index 000000000..ad4d31e02 --- /dev/null +++ b/fluent-package/apt/systemd-test/update-to-next-version-with-auto-and-manual.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/../commonvar.sh + +package="/host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb" + +# Make a dummy pacakge for the next version +dpkg-deb -R /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb tmp +last_ver=$(cat tmp/DEBIAN/control | grep "Version: " | sed -E "s/Version: ([0-9.]+)-([0-9]+)/\2/g") +sed -i -E "s/Version: ([0-9.]+)-([0-9]+)/Version: \1-$(($last_ver+1))/g" tmp/DEBIAN/control +dpkg-deb --build tmp next_version.deb + +# Upgrade package with auto feature +sudo apt install -V -y $package +main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +sudo apt install -V -y ./next_version.deb +test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Main process should be replaced by USR2 signal in auto mode +sleep 15 +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +sudo apt purge -y fluent-package + +# Upgrade package with manual feature +sudo apt install -V -y $package +sed -i 's/=auto/=manual/' /etc/default/fluentd +# TODO: Clarify the specification of FLUENT_PACKAGE_SERVICE_RESTART environment variable +sudo systemctl restart fluentd +main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +sudo apt install -V -y ./next_version.deb +test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Main process should NOT be replaced until USR2 signal fired +sleep 15 +test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +kill -USR2 $main_pid + +# Main process should be replaced by USR2 signal +sleep 15 +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) diff --git a/fluent-package/yum/systemd-test/update-to-next-version-with-auto-and-manual.sh b/fluent-package/yum/systemd-test/update-to-next-version-with-auto-and-manual.sh new file mode 100755 index 000000000..d2e779c31 --- /dev/null +++ b/fluent-package/yum/systemd-test/update-to-next-version-with-auto-and-manual.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/commonvar.sh + +package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm" + +# Make a dummy pacakge for the next version +case $distribution in + amazon) + case $version in + 2023) + curl -L -o rpmrebuild.noarch.rpm https://sourceforge.net/projects/rpmrebuild/files/latest/download + sudo $DNF install -y ./rpmrebuild.noarch.rpm + ;; + 2) + sudo amazon-linux-extras install -y epel + sudo $DNF install -y rpmrebuild + ;; + esac + ;; + *) + sudo $DNF install -y epel-release + sudo $DNF install -y rpmrebuild + ;; +esac + + +# Example: "1.el9" +release=$(rpmquery --queryformat="%{Release}" -p $package) +# Example: "1" +release_ver=$(echo $release | cut -d . -f1) +# Example: "2.el9" +next_release=$(($release_ver+1)).$(echo $release | cut -d. -f2) +rpmrebuild --release=$next_release --modify="find $HOME -name fluentd.service | xargs sed -i -E 's/FLUENT_PACKAGE_VERSION=([0-9.]+)/FLUENT_PACKAGE_VERSION=\1.1/g'" --package $package +next_package=$(find rpmbuild -name "*.rpm") +rpm2cpio $next_package | cpio -id ./usr/lib/systemd/system/fluentd.service +next_package_ver=$(cat ./usr/lib/systemd/system/fluentd.service | grep "FLUENT_PACKAGE_VERSION" | sed -E "s/Environment=FLUENT_PACKAGE_VERSION=(.+)/\1/") +echo "repacked next fluent-package version: $next_package_ver" + +# Upgrade package with auto feature +sudo $DNF install -y $package +sudo systemctl enable --now fluentd +main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +sudo $DNF install -y ./$next_package +test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Main process should be replaced by USR2 signal in auto mode +sleep 15 +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +sudo $DNF remove -y fluent-package + +# Upgrade package with manual feature +sudo $DNF install -y $package +sed -i 's/=auto/=manual/' /etc/sysconfig/fluentd +# TODO: Clarify the specification of FLUENT_PACKAGE_SERVICE_RESTART environment variable +sudo systemctl enable --now fluentd +main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +sudo $DNF install -y ./$next_package +test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Main process should NOT be replaced until USR2 signal fired +sleep 15 +test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +kill -USR2 $main_pid + +# Main process should be replaced by USR2 signal +sleep 15 +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) From 42308407e1333adf45f0ec5b470d286c20b0a2ed Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Thu, 7 Nov 2024 15:54:52 +0900 Subject: [PATCH 15/29] ci deb: check whether needrestart was suppressed Even though needrestart package was installed, service will not be restarted out of the maintainer script (hook). Signed-off-by: Kentaro Hayashi --- .../systemd-test/update-to-next-major-version.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fluent-package/apt/systemd-test/update-to-next-major-version.sh b/fluent-package/apt/systemd-test/update-to-next-major-version.sh index d4542c486..f624e4344 100755 --- a/fluent-package/apt/systemd-test/update-to-next-major-version.sh +++ b/fluent-package/apt/systemd-test/update-to-next-major-version.sh @@ -14,9 +14,23 @@ sudo /opt/fluent/bin/fluent-gem install --no-document gqtp # Install next major version sudo apt install -V -y \ - /host/v6-test/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + /host/v6-test/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb 2>&1 | tee upgrade.log + +# Test: needrestart was suppressed +if dpkg-query --show --showformat='${Version}' needrestart ; then + case $code_name in + focal) + # dpkg-query succeeds even though needrestart is not installed. + (! grep "No services need to be restarted." upgrade.log) + ;; + *) + grep "No services need to be restarted." upgrade.log + ;; + esac +fi # Test: Check whether plugin/gem were installed during upgrading /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat # Non fluent-plugin- prefix gem should not be installed automatically (! /opt/fluent/bin/fluent-gem list | grep gqtp) + From c7f8c36095a7421806746a90bd8e6b0be0b7b696 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Thu, 7 Nov 2024 18:38:54 +0900 Subject: [PATCH 16/29] deb yum: use /usr/sbin/fluent-gem to migrate gems when upgrade Signed-off-by: Shizuo Fujita --- .../templates/package-scripts/fluent-package/deb/preinst | 2 +- fluent-package/yum/fluent-package.spec.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/preinst b/fluent-package/templates/package-scripts/fluent-package/deb/preinst index c01612591..2b90cbc9f 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/preinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/preinst @@ -18,7 +18,7 @@ migrate_local_plugins() { fi # collect list of gems # We don't use fluent-diagtool here because it depends on systemd and piuparts fails - /opt/fluent/bin/fluent-gem list '^fluent-plugin-' --no-version --no-verbose > $local_base_plugins + /usr/sbin/fluent-gem list '^fluent-plugin-' --no-version --no-verbose > $local_base_plugins } case "$1" in diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index 18761e0c1..9009c8714 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -189,7 +189,7 @@ else fi if [ $1 -eq 2 ]; then # collect installed gems during upgrading - /opt/fluent/bin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose > %{local_base_plugins} + /usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose > %{local_base_plugins} fi %preun From 102cdbc5de0ca50528b95e00a4a867a9f46967bf Mon Sep 17 00:00:00 2001 From: Watson Date: Mon, 11 Nov 2024 13:18:58 +0900 Subject: [PATCH 17/29] ci: update the tests for no data lost (#715) Update the test to ensure : * There is no issue even if an upgrade is performed that includes a Ruby major version update. * There is no data loss even if data is sent until the main process is replaced. --------- Signed-off-by: Shizuo Fujita Signed-off-by: Daijiro Fukuda --- ...pdate-to-next-version-without-data-lost.sh | 21 ++++----- ...pdate-to-next-version-without-data-lost.sh | 47 ++++--------------- 2 files changed, 18 insertions(+), 50 deletions(-) diff --git a/fluent-package/apt/systemd-test/update-to-next-version-without-data-lost.sh b/fluent-package/apt/systemd-test/update-to-next-version-without-data-lost.sh index 9f6c5688f..44299798a 100755 --- a/fluent-package/apt/systemd-test/update-to-next-version-without-data-lost.sh +++ b/fluent-package/apt/systemd-test/update-to-next-version-without-data-lost.sh @@ -10,12 +10,6 @@ sudo apt install -V -y rsyslog sudo apt install -V -y \ /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb -# Make a dummy pacakge for the next version -dpkg-deb -R /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb tmp -last_ver=$(cat tmp/DEBIAN/control | grep "Version: " | sed -E "s/Version: ([0-9.]+)-([0-9]+)/\2/g") -sed -i -E "s/Version: ([0-9.]+)-([0-9]+)/Version: \1-$(($last_ver+1))/g" tmp/DEBIAN/control -dpkg-deb --build tmp next_version.deb - # Set up configuration cat < $(dirname $0)/../../test-tools/rsyslog.conf >> /etc/rsyslog.conf cp $(dirname $0)/../../test-tools/fluentd.conf /etc/fluent/fluentd.conf @@ -32,18 +26,21 @@ sleep 1 # Send logs in background for 4 seconds /opt/fluent/bin/ruby $(dirname $0)/../../test-tools/logdata-sender.rb \ - --udp-data-count 50 --tcp-data-count 60 --syslog-data-count 70 --syslog-identifer "test-syslog" --duration 4 & + --udp-data-count 50 --tcp-data-count 60 --syslog-data-count 70 --syslog-identifer "test-syslog" --duration 16 & sleep 1 -# Update to the next version -sudo apt install -V -y ./next_version.deb +# Update to the next major version +sudo apt install -V -y \ + /host/v6-test/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb test $main_pid -eq $(systemctl show --value --property=MainPID fluentd) -sleep 3 +# Main process should be replaced by USR2 signal +sleep 20 +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) # Stop fluentd to flush the logs and check systemctl stop fluentd -test $(wc -l /var/log/fluent/test_udp*.log | cut -d' ' -f 1) = "50" -test $(wc -l /var/log/fluent/test_tcp*.log | cut -d' ' -f 1) = "60" +test $(wc -l /var/log/fluent/test_udp*.log | tail -n 1 | awk '{print $1}') = "50" +test $(wc -l /var/log/fluent/test_tcp*.log | tail -n 1 | awk '{print $1}') = "60" test $(grep "test-syslog" /var/log/fluent/test_syslog*.log | wc -l) = "70" diff --git a/fluent-package/yum/systemd-test/update-to-next-version-without-data-lost.sh b/fluent-package/yum/systemd-test/update-to-next-version-without-data-lost.sh index 7ed39730a..a6d75b39b 100755 --- a/fluent-package/yum/systemd-test/update-to-next-version-without-data-lost.sh +++ b/fluent-package/yum/systemd-test/update-to-next-version-without-data-lost.sh @@ -10,38 +10,6 @@ sudo $DNF install -y rsyslog package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm" sudo $DNF install -y $package -# Make a dummy pacakge for the next version -case $distribution in - amazon) - case $version in - 2023) - curl -L -o rpmrebuild.noarch.rpm https://sourceforge.net/projects/rpmrebuild/files/latest/download - sudo $DNF install -y ./rpmrebuild.noarch.rpm - ;; - 2) - sudo amazon-linux-extras install -y epel - sudo $DNF install -y rpmrebuild - ;; - esac - ;; - *) - sudo $DNF install -y epel-release - sudo $DNF install -y rpmrebuild - ;; -esac - -# Example: "1.el9" -release=$(rpmquery --queryformat="%{Release}" -p $package) -# Example: "1" -release_ver=$(echo $release | cut -d . -f1) -# Example: "2.el9" -next_release=$(($release_ver+1)).$(echo $release | cut -d. -f2) -rpmrebuild --release=$next_release --modify="find $HOME -name fluentd.service | xargs sed -i -E 's/FLUENT_PACKAGE_VERSION=([0-9.]+)/FLUENT_PACKAGE_VERSION=\1.1/g'" --package $package -next_package=$(find rpmbuild -name "*.rpm") -rpm2cpio $next_package | cpio -id ./usr/lib/systemd/system/fluentd.service -next_package_ver=$(cat ./usr/lib/systemd/system/fluentd.service | grep "FLUENT_PACKAGE_VERSION" | sed -E "s/Environment=FLUENT_PACKAGE_VERSION=(.+)/\1/") -echo "repacked next fluent-package version: $next_package_ver" - # Set up configuration cat < $(dirname $0)/../../test-tools/rsyslog.conf >> /etc/rsyslog.conf cp $(dirname $0)/../../test-tools/fluentd.conf /etc/fluent/fluentd.conf @@ -58,18 +26,21 @@ sleep 1 # Send logs in background for 4 seconds /opt/fluent/bin/ruby $(dirname $0)/../../test-tools/logdata-sender.rb \ - --udp-data-count 50 --tcp-data-count 60 --syslog-data-count 70 --syslog-identifer "test-syslog" --duration 4 & + --udp-data-count 50 --tcp-data-count 60 --syslog-data-count 70 --syslog-identifer "test-syslog" --duration 16 & sleep 1 -# Update to the next version -sudo $DNF install -y ./$next_package +# Update to the next major version +next_package="/host/v6-test/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-*.rpm" +sudo $DNF install -y $next_package test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) -sleep 3 +# Main process should be replaced by USR2 signal +sleep 20 +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) # Stop fluentd to flush the logs and check systemctl stop fluentd -test $(wc -l /var/log/fluent/test_udp*.log | cut -d' ' -f 1) = "50" -test $(wc -l /var/log/fluent/test_tcp*.log | cut -d' ' -f 1) = "60" +test $(wc -l /var/log/fluent/test_udp*.log | tail -n 1 | awk '{print $1}') = "50" +test $(wc -l /var/log/fluent/test_tcp*.log | tail -n 1 | awk '{print $1}') = "60" test $(grep "test-syslog" /var/log/fluent/test_syslog*.log | wc -l) = "70" From 20cd970179165dc793899b73e7908249f937f0a4 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Tue, 12 Nov 2024 15:59:03 +0900 Subject: [PATCH 18/29] ci: rename test file Signed-off-by: Shizuo Fujita --- .github/workflows/apt.yml | 2 +- .github/workflows/yum.yml | 4 ++-- ...rsion-without-data-lost.sh => update-without-data-lost.sh} | 0 ...rsion-without-data-lost.sh => update-without-data-lost.sh} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename fluent-package/apt/systemd-test/{update-to-next-version-without-data-lost.sh => update-without-data-lost.sh} (100%) rename fluent-package/yum/systemd-test/{update-to-next-version-without-data-lost.sh => update-without-data-lost.sh} (100%) diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index c446b2457..a4be759b6 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -175,9 +175,9 @@ jobs: - "update-to-next-version-service-status.sh enabled inactive" - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - - "update-to-next-version-without-data-lost.sh" - "update-to-next-version-with-auto-and-manual.sh" - "update-to-next-major-version.sh" + - "update-without-data-lost.sh" include: - label: Debian bullseye amd64 rake-job: debian-bullseye diff --git a/.github/workflows/yum.yml b/.github/workflows/yum.yml index f3b0a97a7..57657e6a1 100644 --- a/.github/workflows/yum.yml +++ b/.github/workflows/yum.yml @@ -150,9 +150,9 @@ jobs: - "update-to-next-version-service-status.sh enabled inactive" - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - - "update-to-next-version-without-data-lost.sh" - "update-to-next-version-with-auto-and-manual.sh" - "update-to-next-major-version.sh" + - "update-without-data-lost.sh" include: - label: AmazonLinux 2 x86_64 rake-job: amazonlinux-2 @@ -221,9 +221,9 @@ jobs: - "update-to-next-version-service-status.sh enabled inactive" - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - - "update-to-next-version-without-data-lost.sh" - "update-to-next-version-with-auto-and-manual.sh" - "update-to-next-major-version.sh" + - "update-without-data-lost.sh" include: - label: RockyLinux 8 x86_64 rake-job: rockylinux-8 diff --git a/fluent-package/apt/systemd-test/update-to-next-version-without-data-lost.sh b/fluent-package/apt/systemd-test/update-without-data-lost.sh similarity index 100% rename from fluent-package/apt/systemd-test/update-to-next-version-without-data-lost.sh rename to fluent-package/apt/systemd-test/update-without-data-lost.sh diff --git a/fluent-package/yum/systemd-test/update-to-next-version-without-data-lost.sh b/fluent-package/yum/systemd-test/update-without-data-lost.sh similarity index 100% rename from fluent-package/yum/systemd-test/update-to-next-version-without-data-lost.sh rename to fluent-package/yum/systemd-test/update-without-data-lost.sh From fa5c6412156dbc7563392fd0f31b2e46e35d1379 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Tue, 12 Nov 2024 16:00:55 +0900 Subject: [PATCH 19/29] ci: add downgrade test for no data lost Signed-off-by: Shizuo Fujita Signed-off-by: Kentaro Hayashi --- .github/workflows/apt.yml | 3 +- .github/workflows/yum.yml | 6 ++- .../systemd-test/update-without-data-lost.sh | 37 ++++++++++++++++--- .../systemd-test/update-without-data-lost.sh | 37 +++++++++++++++++-- 4 files changed, 71 insertions(+), 12 deletions(-) diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index a4be759b6..7e0ef51f7 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -177,7 +177,8 @@ jobs: - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-with-auto-and-manual.sh" - "update-to-next-major-version.sh" - - "update-without-data-lost.sh" + - "update-without-data-lost.sh v5 v6" + - "update-without-data-lost.sh v6 v5" include: - label: Debian bullseye amd64 rake-job: debian-bullseye diff --git a/.github/workflows/yum.yml b/.github/workflows/yum.yml index 57657e6a1..dde7a608a 100644 --- a/.github/workflows/yum.yml +++ b/.github/workflows/yum.yml @@ -152,7 +152,8 @@ jobs: - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-with-auto-and-manual.sh" - "update-to-next-major-version.sh" - - "update-without-data-lost.sh" + - "update-without-data-lost.sh v5 v6" + - "update-without-data-lost.sh v6 v5" include: - label: AmazonLinux 2 x86_64 rake-job: amazonlinux-2 @@ -223,7 +224,8 @@ jobs: - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-with-auto-and-manual.sh" - "update-to-next-major-version.sh" - - "update-without-data-lost.sh" + - "update-without-data-lost.sh v5 v6" + - "update-without-data-lost.sh v6 v5" include: - label: RockyLinux 8 x86_64 rake-job: rockylinux-8 diff --git a/fluent-package/apt/systemd-test/update-without-data-lost.sh b/fluent-package/apt/systemd-test/update-without-data-lost.sh index 44299798a..851edab51 100755 --- a/fluent-package/apt/systemd-test/update-without-data-lost.sh +++ b/fluent-package/apt/systemd-test/update-without-data-lost.sh @@ -4,11 +4,39 @@ set -exu . $(dirname $0)/../commonvar.sh +v5_package="/host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb" +v6_package="/host/v6-test/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb" + +case "$1" in + v5) + package=$v5_package + ;; + v6) + package=$v6_package + ;; + *) + echo "Invalid argument: $1" + exit 1 + ;; +esac + +case "$2" in + v5) + next_package=$v5_package + ;; + v6) + next_package=$v6_package + ;; + *) + echo "Invalid argument: $2" + exit 1 + ;; +esac + sudo apt install -V -y rsyslog # Install the current -sudo apt install -V -y \ - /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb +sudo apt install -V -y $package # Set up configuration cat < $(dirname $0)/../../test-tools/rsyslog.conf >> /etc/rsyslog.conf @@ -30,9 +58,8 @@ sleep 1 sleep 1 -# Update to the next major version -sudo apt install -V -y \ - /host/v6-test/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb +# Update to the next version +sudo apt install -V -y --allow-downgrades $next_package test $main_pid -eq $(systemctl show --value --property=MainPID fluentd) # Main process should be replaced by USR2 signal diff --git a/fluent-package/yum/systemd-test/update-without-data-lost.sh b/fluent-package/yum/systemd-test/update-without-data-lost.sh index a6d75b39b..f63a86cd8 100755 --- a/fluent-package/yum/systemd-test/update-without-data-lost.sh +++ b/fluent-package/yum/systemd-test/update-without-data-lost.sh @@ -4,10 +4,40 @@ set -exu . $(dirname $0)/commonvar.sh +v5_package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-*.rpm" +v6_package="/host/v6-test/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-*.rpm" + +case "$1" in + v5) + package=$v5_package + ;; + v6) + package=$v6_package + ;; + *) + echo "Invalid argument: $1" + exit 1 + ;; +esac + +command="install" +case "$2" in + v5) + next_package=$v5_package + command="downgrade" # Avoid error in AmazonLinux2 + ;; + v6) + next_package=$v6_package + ;; + *) + echo "Invalid argument: $2" + exit 1 + ;; +esac + sudo $DNF install -y rsyslog # Install the current -package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm" sudo $DNF install -y $package # Set up configuration @@ -30,9 +60,8 @@ sleep 1 sleep 1 -# Update to the next major version -next_package="/host/v6-test/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-*.rpm" -sudo $DNF install -y $next_package +# Update to the next version +sudo $DNF $command -y $next_package test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) # Main process should be replaced by USR2 signal From 28a09667ad202436c32af380f9d6f5458994514d Mon Sep 17 00:00:00 2001 From: Watson Date: Thu, 21 Nov 2024 11:23:53 +0900 Subject: [PATCH 20/29] deb: use auto/manual feature when old package supports (#738) This PR will allow to switch auto/manual restart settings with DEB package even when Fluentd is running. --------- Signed-off-by: Shizuo Fujita Signed-off-by: Daijiro Fukuda --- ...update-to-next-version-with-auto-and-manual.sh | 3 +-- .../package-scripts/fluent-package/deb/postinst | 11 ++++++++--- .../package-scripts/fluent-package/deb/preinst | 15 +++++++++++++++ ...update-to-next-version-with-auto-and-manual.sh | 3 +-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/fluent-package/apt/systemd-test/update-to-next-version-with-auto-and-manual.sh b/fluent-package/apt/systemd-test/update-to-next-version-with-auto-and-manual.sh index ad4d31e02..63f2646f6 100755 --- a/fluent-package/apt/systemd-test/update-to-next-version-with-auto-and-manual.sh +++ b/fluent-package/apt/systemd-test/update-to-next-version-with-auto-and-manual.sh @@ -27,9 +27,8 @@ sudo apt purge -y fluent-package # Upgrade package with manual feature sudo apt install -V -y $package +sudo systemctl enable --now fluentd sed -i 's/=auto/=manual/' /etc/default/fluentd -# TODO: Clarify the specification of FLUENT_PACKAGE_SERVICE_RESTART environment variable -sudo systemctl restart fluentd main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) sudo apt install -V -y ./next_version.deb diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postinst b/fluent-package/templates/package-scripts/fluent-package/deb/postinst index 679264d99..3cec81a0b 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postinst @@ -168,13 +168,17 @@ install_missing_plugins() { fi } +zero_downtime_restart_supported=/tmp/<%= package_dir %>/.zero_downtime_restart_supported fluentd_auto_restart() { + if [ ! -e "$zero_downtime_restart_supported" ]; then + return + fi + if [ -d /run/systemd/system ]; then pid=$(systemctl show <%= service_name %> --property=MainPID --value) if [ $pid -ne 0 ]; then - env_vars=$(sed -e 's/\x0/\n/g' /proc/$pid/environ) - action=$(eval $env_vars && echo $FLUENT_PACKAGE_SERVICE_RESTART) - case "$action" in + . /etc/default/<%= service_name %> + case "$FLUENT_PACKAGE_SERVICE_RESTART" in auto) echo "Kick auto service upgrade mode to MainPID:$pid" kill -USR2 $pid @@ -188,6 +192,7 @@ fluentd_auto_restart() { esac fi fi + rm -rf $zero_downtime_restart_supported } case "$1" in diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/preinst b/fluent-package/templates/package-scripts/fluent-package/deb/preinst index 2b90cbc9f..95097d6ab 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/preinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/preinst @@ -21,9 +21,24 @@ migrate_local_plugins() { /usr/sbin/fluent-gem list '^fluent-plugin-' --no-version --no-verbose > $local_base_plugins } +zero_downtime_restart_supported_version="1.18.0" +zero_downtime_restart_supported=/tmp/<%= package_dir %>/.zero_downtime_restart_supported +check_version() { + printf '%s\n' "$zero_downtime_restart_supported_version" "$1" | sort --check=quiet --version-sort +} +check_whether_zero_downtime_restart_supported() { + current_version=$(/usr/sbin/fluentd --version | cut -d' ' -f 4) + if check_version $current_version; then + echo "Fluentd $current_version supports zero downtime restart." + mkdir -p /tmp/<%= package_dir %> + touch $zero_downtime_restart_supported + fi +} + case "$1" in upgrade) migrate_local_plugins + check_whether_zero_downtime_restart_supported ;; abort-upgrade) ;; diff --git a/fluent-package/yum/systemd-test/update-to-next-version-with-auto-and-manual.sh b/fluent-package/yum/systemd-test/update-to-next-version-with-auto-and-manual.sh index d2e779c31..03db0da23 100755 --- a/fluent-package/yum/systemd-test/update-to-next-version-with-auto-and-manual.sh +++ b/fluent-package/yum/systemd-test/update-to-next-version-with-auto-and-manual.sh @@ -55,9 +55,8 @@ sudo $DNF remove -y fluent-package # Upgrade package with manual feature sudo $DNF install -y $package -sed -i 's/=auto/=manual/' /etc/sysconfig/fluentd -# TODO: Clarify the specification of FLUENT_PACKAGE_SERVICE_RESTART environment variable sudo systemctl enable --now fluentd +sed -i 's/=auto/=manual/' /etc/sysconfig/fluentd main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) sudo $DNF install -y ./$next_package From e27dee9ae3906016831ad268140578ce78a1189c Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Thu, 5 Dec 2024 16:50:09 +0900 Subject: [PATCH 21/29] remove unnecessary debug logs Signed-off-by: Daijiro Fukuda --- .../package-scripts/fluent-package/deb/postinst | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postinst b/fluent-package/templates/package-scripts/fluent-package/deb/postinst index 3cec81a0b..b8771b402 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postinst @@ -221,13 +221,3 @@ fi <% end %> #DEBHELPER# - -. /etc/default/<%= service_name %> -echo "FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" -case "$FLUENT_PACKAGE_SERVICE_RESTART" in - auto|manual) - echo "FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" - ;; - *) - ;; -esac From 2e109bf233ce00867856da09b5bf33b1a31ca838 Mon Sep 17 00:00:00 2001 From: Watson Date: Mon, 9 Dec 2024 10:51:47 +0900 Subject: [PATCH 22/29] deb: include prerm script in debian package (#757) Add missing `prerm` script to include it in debian package Signed-off-by: Shizuo Fujita Signed-off-by: Daijiro Fukuda --- fluent-package/Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-package/Rakefile b/fluent-package/Rakefile index 3d1f8c579..84c7a2caa 100755 --- a/fluent-package/Rakefile +++ b/fluent-package/Rakefile @@ -494,7 +494,7 @@ class BuildTask remove_needless_files end - debian_pkg_scripts = ["preinst", "postinst", "postrm"] + debian_pkg_scripts = ["preinst", "postinst", "prerm", "postrm"] debian_pkg_scripts.each do |script| CLEAN.include(File.join("..", "debian", script)) end From abb317e6fc078b8f3ce29d4fc453c5fc5f312b6a Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Mon, 9 Dec 2024 12:08:44 +0900 Subject: [PATCH 23/29] auto plugin install: disable unless auto (#756) This allows users to manually manage plugins by setting FLUENT_PACKAGE_SERVICE_RESTART to manual. For example, there will be cases where a user wants to use a particular plugin version. Signed-off-by: Daijiro Fukuda --- .github/workflows/apt.yml | 4 +++- .github/workflows/yum.yml | 8 ++++++-- .../update-to-next-major-version.sh | 17 ++++++++++++++--- .../package-scripts/fluent-package/deb/preinst | 5 +++++ fluent-package/yum/fluent-package.spec.in | 8 ++++++-- .../update-to-next-major-version.sh | 17 ++++++++++++++--- 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index 7e0ef51f7..3c3e7c848 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -176,7 +176,9 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-with-auto-and-manual.sh" - - "update-to-next-major-version.sh" + - "update-to-next-major-version.sh auto" + - "update-to-next-major-version.sh manual" + - "update-to-next-major-version.sh etc" - "update-without-data-lost.sh v5 v6" - "update-without-data-lost.sh v6 v5" include: diff --git a/.github/workflows/yum.yml b/.github/workflows/yum.yml index dde7a608a..b46cdc618 100644 --- a/.github/workflows/yum.yml +++ b/.github/workflows/yum.yml @@ -151,7 +151,9 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-with-auto-and-manual.sh" - - "update-to-next-major-version.sh" + - "update-to-next-major-version.sh auto" + - "update-to-next-major-version.sh manual" + - "update-to-next-major-version.sh etc" - "update-without-data-lost.sh v5 v6" - "update-without-data-lost.sh v6 v5" include: @@ -223,7 +225,9 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-with-auto-and-manual.sh" - - "update-to-next-major-version.sh" + - "update-to-next-major-version.sh auto" + - "update-to-next-major-version.sh manual" + - "update-to-next-major-version.sh etc" - "update-without-data-lost.sh v5 v6" - "update-without-data-lost.sh v6 v5" include: diff --git a/fluent-package/apt/systemd-test/update-to-next-major-version.sh b/fluent-package/apt/systemd-test/update-to-next-major-version.sh index f624e4344..9add0d328 100755 --- a/fluent-package/apt/systemd-test/update-to-next-major-version.sh +++ b/fluent-package/apt/systemd-test/update-to-next-major-version.sh @@ -4,10 +4,15 @@ set -exu . $(dirname $0)/../commonvar.sh +service_restart=$1 + # Install the current sudo apt install -V -y \ /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb +# Set FLUENT_PACKAGE_SERVICE_RESTART +sed -i "s/=auto/=$service_restart/" /etc/default/fluentd + # Install plugin manually (plugin and gem) sudo /opt/fluent/bin/fluent-gem install --no-document fluent-plugin-concat sudo /opt/fluent/bin/fluent-gem install --no-document gqtp @@ -30,7 +35,13 @@ if dpkg-query --show --showformat='${Version}' needrestart ; then fi # Test: Check whether plugin/gem were installed during upgrading -/opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat -# Non fluent-plugin- prefix gem should not be installed automatically -(! /opt/fluent/bin/fluent-gem list | grep gqtp) +if [ "$service_restart" = auto ]; then + # plugin gem should be installed automatically + /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat + # Non fluent-plugin- prefix gem should not be installed automatically + (! /opt/fluent/bin/fluent-gem list | grep gqtp) +else + # plugin gem should not be installed automatically + (! /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat) +fi diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/preinst b/fluent-package/templates/package-scripts/fluent-package/deb/preinst index 95097d6ab..02d856f6a 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/preinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/preinst @@ -12,6 +12,9 @@ set -e local_base_plugins=/tmp/<%= package_dir %>/.local_base_plugins migrate_local_plugins() { + if [ "$FLUENT_PACKAGE_SERVICE_RESTART" != auto ]; then + return + fi if [ ! -d /run/systemd/system ]; then # tmpfiles.d owns /tmp/<%= package_dir %>, but not created without systemd mkdir -p /tmp/<%= package_dir %> @@ -37,6 +40,8 @@ check_whether_zero_downtime_restart_supported() { case "$1" in upgrade) + . /etc/default/<%= service_name %> + echo "preinst FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" migrate_local_plugins check_whether_zero_downtime_restart_supported ;; diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index 9009c8714..590dbb7d9 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -188,8 +188,12 @@ else fi fi if [ $1 -eq 2 ]; then - # collect installed gems during upgrading - /usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose > %{local_base_plugins} + . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ + echo "pre FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" + if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = auto ]; then + # collect installed gems during upgrading + /usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose > %{local_base_plugins} + fi fi %preun diff --git a/fluent-package/yum/systemd-test/update-to-next-major-version.sh b/fluent-package/yum/systemd-test/update-to-next-major-version.sh index ff88f70ad..4aa1131f3 100755 --- a/fluent-package/yum/systemd-test/update-to-next-major-version.sh +++ b/fluent-package/yum/systemd-test/update-to-next-major-version.sh @@ -4,10 +4,15 @@ set -exu . $(dirname $0)/commonvar.sh +service_restart=$1 + # Install the current package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-*.rpm" sudo $DNF install -y $package +# Set FLUENT_PACKAGE_SERVICE_RESTART +sed -i "s/=auto/=$service_restart/" /etc/sysconfig/fluentd + # Install plugin manually (plugin and gem) sudo /opt/fluent/bin/fluent-gem install --no-document fluent-plugin-concat sudo /opt/fluent/bin/fluent-gem install --no-document gqtp @@ -17,6 +22,12 @@ package="/host/v6-test/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/f sudo $DNF install -y $package # Test: Check whether plugin/gem were installed during upgrading -/opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat -# Non fluent-plugin- prefix gem should not be installed automatically -(! /opt/fluent/bin/fluent-gem list | grep gqtp) +if [ "$service_restart" = auto ]; then + # plugin gem should be installed automatically + /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat + # Non fluent-plugin- prefix gem should not be installed automatically + (! /opt/fluent/bin/fluent-gem list | grep gqtp) +else + # plugin gem should not be installed automatically + (! /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat) +fi From 4fed1fe4ea2578ec0b6410de3e82900a2dc67057 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Mon, 9 Dec 2024 15:02:50 +0900 Subject: [PATCH 24/29] deb rpm: remove manual feature of zero-downtime-restart from uninstall phase (#758) We were going to support two methods of downgrading with zero downtime. 1. Running v6.x => Install v5.x package by overwriting 2. Running v6.x => Replace `FLUENT_PACKAGE_SERVICE_RESTART` value to `manual` => uninstall v6.x => Install v5.x The second method is to keep the Fluentd process running after uninstalling it. We decided to remove `2.` method because it may cause confusion for users. Signed-off-by: Shizuo Fujita --- .../package-scripts/fluent-package/deb/prerm | 14 +------------- fluent-package/yum/fluent-package.spec.in | 13 +------------ 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/prerm b/fluent-package/templates/package-scripts/fluent-package/deb/prerm index 37b6d9c49..83004fdd1 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/prerm +++ b/fluent-package/templates/package-scripts/fluent-package/deb/prerm @@ -33,18 +33,6 @@ esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. -. /etc/default/<%= service_name %> -if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "manual" ]; then - # Do not stop service because removing package will be executed - # for major downgrade (e.g. uninstall v6 then reinstall v5) - # In such a case, missing plugins for v5 cause trouble in - # restarting service. - # so instead of restarting service here, demand users to install - # such plugins in advance then delegate users to restart service - # manually later. - : -else - #DEBHELPER# -fi +#DEBHELPER# exit 0 diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index 590dbb7d9..ec5f56c29 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -197,18 +197,7 @@ if [ $1 -eq 2 ]; then fi %preun -. %{_sysconfdir}/sysconfig/@SERVICE_NAME@ -echo "preun FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" -if [ $1 -eq 0 ]; then - if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "manual" ]; then - # When rollback to previous version, there is a case that user want to - # restart manually to reduce downtime. - : - else - # disable service here - %systemd_preun @SERVICE_NAME@.service - fi -fi +%systemd_preun @SERVICE_NAME@.service %post . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ From c2821b0b4493ac71d0c271197e883a7b94bb929c Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Tue, 10 Dec 2024 11:05:21 +0900 Subject: [PATCH 25/29] rpm: revert suppressing systemd_post macro (#759) We don't need to suppress this macro because this macro handles preset, not restart. I have confirmed that this macro of the package for RHEL 9 is expanded as follows. ```bash if [ $1 -eq 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # Initial installation /usr/lib/systemd/systemd-update-helper install-system-units fluentd.service || : fi ``` Signed-off-by: Daijiro Fukuda --- fluent-package/yum/fluent-package.spec.in | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index ec5f56c29..c3b50eb8d 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -200,15 +200,7 @@ fi %systemd_preun @SERVICE_NAME@.service %post -. %{_sysconfdir}/sysconfig/@SERVICE_NAME@ -echo "post FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" -if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "auto" ]; then - echo "Suppress auto restart in auto mode..." -elif [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "manual" ]; then - echo "Suppress auto restart in manual mode ..." -else - %systemd_post @SERVICE_NAME@.service -fi +%systemd_post @SERVICE_NAME@.service if [ $1 -eq 1 ]; then if [ -d /etc/@COMPAT_PACKAGE_DIR@ -a ! -h /etc/@COMPAT_PACKAGE_DIR@ ]; then touch %{v4migration} From 4a06888d5a0cebc030e7093721ce15d51c7ba3d3 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Tue, 10 Dec 2024 19:43:22 +0900 Subject: [PATCH 26/29] system-test: add update test from v5 LTS and downgrade test to v5 LTS (#761) Signed-off-by: Shizuo Fujita Signed-off-by: Daijiro Fukuda Co-authored-by: Daijiro Fukuda --- .github/workflows/apt.yml | 2 + .github/workflows/yum.yml | 4 + fluent-package/apt/commonvar.sh | 2 + .../apt/systemd-test/downgrade-to-v5-lts.sh | 28 +++++++ .../apt/systemd-test/update-from-v5-lts.sh | 69 ++++++++++++++++ fluent-package/yum/systemd-test/commonvar.sh | 1 + .../yum/systemd-test/downgrade-to-v5-lts.sh | 46 +++++++++++ .../yum/systemd-test/update-from-v5-lts.sh | 79 +++++++++++++++++++ 8 files changed, 231 insertions(+) create mode 100755 fluent-package/apt/systemd-test/downgrade-to-v5-lts.sh create mode 100755 fluent-package/apt/systemd-test/update-from-v5-lts.sh create mode 100755 fluent-package/yum/systemd-test/downgrade-to-v5-lts.sh create mode 100755 fluent-package/yum/systemd-test/update-from-v5-lts.sh diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index 3c3e7c848..1c3da5ae1 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -165,7 +165,9 @@ jobs: - "update-from-v4.sh local" - "update-from-v4.sh v5" - "update-from-v4.sh lts" + - "update-from-v5-lts.sh" - "downgrade-to-v4.sh" + - "downgrade-to-v5-lts.sh" - "install-newly.sh local" - "install-newly.sh v5" - "install-newly.sh lts" diff --git a/.github/workflows/yum.yml b/.github/workflows/yum.yml index b46cdc618..f3a4843ea 100644 --- a/.github/workflows/yum.yml +++ b/.github/workflows/yum.yml @@ -140,7 +140,9 @@ jobs: - AmazonLinux 2023 x86_64 test: - "update-from-v4.sh" + - "update-from-v5-lts.sh" - "downgrade-to-v4.sh" + - "downgrade-to-v5-lts.sh" - "install-newly.sh local" - "install-newly.sh v5" - "install-newly.sh lts" @@ -214,7 +216,9 @@ jobs: - AlmaLinux 9 x86_64 test: - "update-from-v4.sh" + - "update-from-v5-lts.sh" - "downgrade-to-v4.sh" + - "downgrade-to-v5-lts.sh" - "install-newly.sh local" - "install-newly.sh v5" - "install-newly.sh lts" diff --git a/fluent-package/apt/commonvar.sh b/fluent-package/apt/commonvar.sh index 11147319b..597bb131f 100644 --- a/fluent-package/apt/commonvar.sh +++ b/fluent-package/apt/commonvar.sh @@ -3,6 +3,8 @@ architecture=$(dpkg --print-architecture) repositories_dir=/fluentd/fluent-package/apt/repositories java_jdk=openjdk-11-jre td_agent_version=4.5.2 +fluent_package_lts_version=5.0.5 + case ${code_name} in xenial) distribution=ubuntu diff --git a/fluent-package/apt/systemd-test/downgrade-to-v5-lts.sh b/fluent-package/apt/systemd-test/downgrade-to-v5-lts.sh new file mode 100755 index 000000000..50ac15e50 --- /dev/null +++ b/fluent-package/apt/systemd-test/downgrade-to-v5-lts.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/../commonvar.sh + +# Install v5 LTS to register the repository +curl --fail --silent --show-error --location https://toolbelt.treasuredata.com/sh/install-${distribution}-${code_name}-fluent-package5-lts.sh | sh + +sudo apt purge -y fluent-package + +# Install the current +sudo apt install -V -y \ + /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +# Test: service status +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent +main_pid=$(eval $(systemctl show td-agent --property=MainPID) && echo $MainPID) + +# Downgrade to v5 LTS +apt install -V -y fluent-package=${fluent_package_lts_version}-1 --allow-downgrades + +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent + +# Fluentd should be restarted. +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) diff --git a/fluent-package/apt/systemd-test/update-from-v5-lts.sh b/fluent-package/apt/systemd-test/update-from-v5-lts.sh new file mode 100755 index 000000000..9baa72fba --- /dev/null +++ b/fluent-package/apt/systemd-test/update-from-v5-lts.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/../commonvar.sh + + +# If it update from v5 LTS without stopping Fluentd, Fluentd will not be restarted. +# Install v5 LTS +curl --fail --silent --show-error --location https://toolbelt.treasuredata.com/sh/install-${distribution}-${code_name}-fluent-package5-lts.sh | sh + +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent +main_pid=$(eval $(systemctl show td-agent --property=MainPID) && echo $MainPID) + +# Install the current +sudo apt install -V -y \ + /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +# Test: service status +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent + +# Fluentd should NOT be restarted. +test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +apt purge -y fluent-package + +# If it update from v5 LTS with stopping Fluentd, Fluentd will be started when service is enabled. +# Install v5 LTS +curl --fail --silent --show-error --location https://toolbelt.treasuredata.com/sh/install-${distribution}-${code_name}-fluent-package5-lts.sh | sh + +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent +main_pid=$(eval $(systemctl show td-agent --property=MainPID) && echo $MainPID) + +systemctl stop fluentd + +# Install the current +sudo apt install -V -y \ + /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb + +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent + +# Fluentd should be started if service was stopped before update. +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Test: environmental variables +pid=$(systemctl show fluentd --property=MainPID --value) +env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ) +test $(eval $env_vars && echo $HOME) = "/var/lib/fluent" +test $(eval $env_vars && echo $LOGNAME) = "_fluentd" +test $(eval $env_vars && echo $USER) = "_fluentd" +test $(eval $env_vars && echo $FLUENT_CONF) = "/etc/fluent/fluentd.conf" +test $(eval $env_vars && echo $FLUENT_PACKAGE_LOG_FILE) = "/var/log/fluent/fluentd.log" +test $(eval $env_vars && echo $FLUENT_PLUGIN) = "/etc/fluent/plugin" +test $(eval $env_vars && echo $FLUENT_SOCKET) = "/var/run/fluent/fluentd.sock" + +# Test: No error logs +# (v5 default config outputs 'warn' log, so we should check only 'error' and 'fatal' logs) +sleep 3 +test -e /var/log/fluent/fluentd.log +(! grep -e '\[error\]' -e '\[fatal\]' /var/log/fluent/fluentd.log) + +# Test: Guard duplicated instance +(! sudo /usr/sbin/fluentd) +(! sudo /usr/sbin/fluentd -v) +sudo /usr/sbin/fluentd --dry-run diff --git a/fluent-package/yum/systemd-test/commonvar.sh b/fluent-package/yum/systemd-test/commonvar.sh index 9a847fd8a..234de734f 100755 --- a/fluent-package/yum/systemd-test/commonvar.sh +++ b/fluent-package/yum/systemd-test/commonvar.sh @@ -3,6 +3,7 @@ distribution=$(cat /etc/system-release-cpe | awk '{print substr($1, index($1, "o"))}' | cut -d: -f2) version=$(cat /etc/system-release-cpe | awk '{print substr($1, index($1, "o"))}' | cut -d: -f4) td_agent_version=4.5.2 +fluent_package_lts_version=5.0.5 case $distribution in amazon) diff --git a/fluent-package/yum/systemd-test/downgrade-to-v5-lts.sh b/fluent-package/yum/systemd-test/downgrade-to-v5-lts.sh new file mode 100755 index 000000000..a0dd8af01 --- /dev/null +++ b/fluent-package/yum/systemd-test/downgrade-to-v5-lts.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/commonvar.sh + +# Install v5 LTS to register the repository +case $distribution in + amazon) + case $version in + 2023) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2023-fluent-package5-lts.sh | sh + ;; + 2) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2-fluent-package5-lts.sh | sh + ;; + esac + ;; + *) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package5-lts.sh | sh + ;; +esac + +sudo $DNF remove -y fluent-package + +# Install the current +sudo $DNF install -y \ + /host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm + +sudo systemctl enable --now fluentd +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent +main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Downgrade to v5 LTS +sudo $DNF downgrade -y fluent-package-${fluent_package_lts_version} + +# Test: take over enabled state +systemctl is-enabled fluentd + +# Test: service status +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent + +# Fluentd should be restarted. +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) diff --git a/fluent-package/yum/systemd-test/update-from-v5-lts.sh b/fluent-package/yum/systemd-test/update-from-v5-lts.sh new file mode 100755 index 000000000..b51b0959c --- /dev/null +++ b/fluent-package/yum/systemd-test/update-from-v5-lts.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +set -exu + +. $(dirname $0)/commonvar.sh + +# If it update from v5 LTS without stopping Fluentd, Fluentd will be restarted. +# Install v5 LTS +case $distribution in + amazon) + case $version in + 2023) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2023-fluent-package5-lts.sh | sh + ;; + 2) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-amazon2-fluent-package5-lts.sh | sh + ;; + esac + ;; + *) + curl -fsSL https://toolbelt.treasuredata.com/sh/install-redhat-fluent-package5-lts.sh | sh + ;; +esac + +sudo systemctl enable --now fluentd +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent +main_pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Install the current +sudo $DNF install -y \ + /host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm + +# Test: take over enabled state +systemctl is-enabled fluentd + +# Test: service status +systemctl status --no-pager fluentd +systemctl status --no-pager td-agent + +# Fluentd should be restarted when update from v5 LTS. +test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# Test: environmental variables +pid=$(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) +env_vars=$(sudo sed -e 's/\x0/\n/g' /proc/$pid/environ) +test $(eval $env_vars && echo $HOME) = "/var/lib/fluent" +test $(eval $env_vars && echo $LOGNAME) = "fluentd" +test $(eval $env_vars && echo $USER) = "fluentd" +test $(eval $env_vars && echo $FLUENT_CONF) = "/etc/fluent/fluentd.conf" +test $(eval $env_vars && echo $FLUENT_PACKAGE_LOG_FILE) = "/var/log/fluent/fluentd.log" +test $(eval $env_vars && echo $FLUENT_PLUGIN) = "/etc/fluent/plugin" +test $(eval $env_vars && echo $FLUENT_SOCKET) = "/var/run/fluent/fluentd.sock" + +# Test: No error logs +# (v5 default config outputs 'warn' log, so we should check only 'error' and 'fatal' logs) +sleep 3 +test -e /var/log/fluent/fluentd.log +(! grep -e '\[error\]' -e '\[fatal\]' /var/log/fluent/fluentd.log) + +# Test: Guard duplicated instance +(! sudo /usr/sbin/fluentd) +(! sudo /usr/sbin/fluentd -v) +sudo /usr/sbin/fluentd --dry-run + +# Uninstall +sudo $DNF remove -y fluent-package +sudo systemctl daemon-reload + +getent passwd fluentd >/dev/null +getent group fluentd >/dev/null + +# `sudo systemctl daemon-reload` clears the service completely. +# (The result of `systemctl status` will be `unfound`) +# Note: RPM does not leave links like `@/etc/systemd/system/fluentd.service`. +# (Different from deb) + +(! systemctl status --no-pager td-agent) +(! systemctl status --no-pager fluentd) From 262d113f544b3505b4c9dd13a4f4ac3b0bc6f0ea Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Wed, 11 Dec 2024 15:01:39 +0900 Subject: [PATCH 27/29] deb: improve process timing for safety and simplicity (#762) Points * FROM-package just leaves tmp files if it supports the features. * TO-package trigger the features if there are those tmp files. * Thus, we don't need to check the version. * Make installing plugin and restarting the same condition. Before 1. from-prerm(upgrade): Do nothing. 2. to-preinst(upgrade): Collect plugin-list. Confirm version. 3. Install TO-package 4. from-postrm(upgrade): Do nothing. 5. Uninstall FROM-package 6. to-postinst(configure): Install plugin and restart if need. After 1. from-prerm(upgrade): * Check auto or not. * Leave plugin-list and pid if need. 2. to-preinst(upgrade): Set tmp files for TO-package. 3. Install TO-package 4. from-postrm(upgrade): Clean tmp files of FROM-package. 5. Uninstall FROM-package 6. to-postinst(configure): Install plugin and restart if need. Signed-off-by: Daijiro Fukuda --- .../fluent-package/deb/postinst | 30 ++++-------- .../package-scripts/fluent-package/deb/postrm | 8 ++++ .../fluent-package/deb/preinst | 41 ++++++----------- .../package-scripts/fluent-package/deb/prerm | 46 ++++++++++++++++--- 4 files changed, 69 insertions(+), 56 deletions(-) diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postinst b/fluent-package/templates/package-scripts/fluent-package/deb/postinst index b8771b402..8042204f7 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postinst @@ -145,7 +145,7 @@ migration_from_v4_post_process() { fi } -local_base_plugins=/tmp/<%= package_dir %>/.local_base_plugins +local_base_plugins="/tmp/<%= package_dir %>/.previous_plugin_list" install_missing_plugins() { # Install missing gems (even though systemd is not available, it works) if [ -f $local_base_plugins ]; then @@ -168,31 +168,17 @@ install_missing_plugins() { fi } -zero_downtime_restart_supported=/tmp/<%= package_dir %>/.zero_downtime_restart_supported +pid_for_auto_restart="/tmp/<%= package_dir %>/.pid_for_auto_restart" fluentd_auto_restart() { - if [ ! -e "$zero_downtime_restart_supported" ]; then + if [ ! -f "$pid_for_auto_restart" ]; then return fi - if [ -d /run/systemd/system ]; then - pid=$(systemctl show <%= service_name %> --property=MainPID --value) - if [ $pid -ne 0 ]; then - . /etc/default/<%= service_name %> - case "$FLUENT_PACKAGE_SERVICE_RESTART" in - auto) - echo "Kick auto service upgrade mode to MainPID:$pid" - kill -USR2 $pid - ;; - manual) - echo "No need to restart service in manual mode..." - ;; - *) - echo "Nothing to be done..." - ;; - esac - fi - fi - rm -rf $zero_downtime_restart_supported + pid=$(cat "$pid_for_auto_restart") + echo "Kick auto restart to MainPID:$pid" + kill -USR2 $pid + + rm -f "$pid_for_auto_restart" } case "$1" in diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/postrm b/fluent-package/templates/package-scripts/fluent-package/deb/postrm index c43e678b0..6e98aa3ab 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/postrm +++ b/fluent-package/templates/package-scripts/fluent-package/deb/postrm @@ -60,6 +60,11 @@ purge_bin_symlinks() { fi } +purge_tmp_files_for_upgrade() { + rm -f "/tmp/<%= package_dir %>/.plugin_list" + rm -f "/tmp/<%= package_dir %>/.main_pid" +} + case $1 in remove) purge_var_run @@ -72,6 +77,9 @@ case $1 in purge_users purge_bin_symlinks ;; + upgrade) + purge_tmp_files_for_upgrade + ;; *) # nothing to do for upgrade, failed-upgrade, abort-install, abort-upgrade ;; diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/preinst b/fluent-package/templates/package-scripts/fluent-package/deb/preinst index 02d856f6a..96e478104 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/preinst +++ b/fluent-package/templates/package-scripts/fluent-package/deb/preinst @@ -10,40 +10,25 @@ set -e # for details, see https://www.debian.org/doc/debian-policy/ or # the debian-policy package. -local_base_plugins=/tmp/<%= package_dir %>/.local_base_plugins -migrate_local_plugins() { - if [ "$FLUENT_PACKAGE_SERVICE_RESTART" != auto ]; then - return +mark_auto_restart_ready() { + # Copy tmp files made by FROM-side because they should be cleaned postrm of FROM-side. + # (To ensure cleanup, tmp files should be cleaned by its own-side). + # The sequence of these tmp files is as follows: + # 1. FROM-prerm(upgrade): Leave tmp files if need. + # 2. TO-preinst(upgrade): Copy tmp files for TO-side. + # 3. FROM-postrm(upgrade): Clean tmp files of FROM-side(1.). + # 4. TO-postinst(configure): Use and clean tmp files of TO-side(2.). + if [ -f "/tmp/<%= package_dir %>/.plugin_list" ]; then + cp "/tmp/<%= package_dir %>/.plugin_list" "/tmp/<%= package_dir %>/.previous_plugin_list" fi - if [ ! -d /run/systemd/system ]; then - # tmpfiles.d owns /tmp/<%= package_dir %>, but not created without systemd - mkdir -p /tmp/<%= package_dir %> - fi - # collect list of gems - # We don't use fluent-diagtool here because it depends on systemd and piuparts fails - /usr/sbin/fluent-gem list '^fluent-plugin-' --no-version --no-verbose > $local_base_plugins -} - -zero_downtime_restart_supported_version="1.18.0" -zero_downtime_restart_supported=/tmp/<%= package_dir %>/.zero_downtime_restart_supported -check_version() { - printf '%s\n' "$zero_downtime_restart_supported_version" "$1" | sort --check=quiet --version-sort -} -check_whether_zero_downtime_restart_supported() { - current_version=$(/usr/sbin/fluentd --version | cut -d' ' -f 4) - if check_version $current_version; then - echo "Fluentd $current_version supports zero downtime restart." - mkdir -p /tmp/<%= package_dir %> - touch $zero_downtime_restart_supported + if [ -f "/tmp/<%= package_dir %>/.main_pid" ]; then + cp "/tmp/<%= package_dir %>/.main_pid" "/tmp/<%= package_dir %>/.pid_for_auto_restart" fi } case "$1" in upgrade) - . /etc/default/<%= service_name %> - echo "preinst FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" - migrate_local_plugins - check_whether_zero_downtime_restart_supported + mark_auto_restart_ready ;; abort-upgrade) ;; diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/prerm b/fluent-package/templates/package-scripts/fluent-package/deb/prerm index 83004fdd1..5e516d762 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/prerm +++ b/fluent-package/templates/package-scripts/fluent-package/deb/prerm @@ -16,18 +16,52 @@ set -e # for details, see https://www.debian.org/doc/debian-policy/ or # the debian-policy package. +make_sure_working_dir_exists() { + # This func is for CI ONLY. + # Some CI cases don't provide env with systemd. + # tmpfiles.d owns /tmp/<%= package_dir %>, but not created without systemd + if [ -d /run/systemd/system ]; then + return + fi + mkdir -p "/tmp/<%= package_dir %>" +} -case "$1" in - remove|upgrade|deconfigure) - ;; +leave_info_for_auto_restart_if_need() { + # Some CI cases that don't provide env with systemd, so disable auto restart feature in those cases. + if [ ! -d /run/systemd/system ]; then + return + fi - failed-upgrade) - ;; + pid="$(systemctl show "<%= service_name %>" --property=MainPID --value)" + if [ $pid -eq 0 ]; then + echo "Do not use auto restart because the service is not active" + return + fi + + . "/etc/default/<%= service_name %>" + echo "FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" + if [ "$FLUENT_PACKAGE_SERVICE_RESTART" != auto ]; then + return + fi + + /usr/sbin/fluent-gem list '^fluent-plugin-' --no-version --no-verbose > "/tmp/<%= package_dir %>/.plugin_list" + echo "$pid" > "/tmp/<%= package_dir %>/.main_pid" +} + +case "$1" in + upgrade) + make_sure_working_dir_exists + leave_info_for_auto_restart_if_need + ;; + remove|deconfigure) + ;; + failed-upgrade) + ;; *) echo "prerm called with unknown argument '$1'" >&2 exit 1 - ;; + ;; esac # dh_installdeb will replace this with shell code automatically From 038b7704db75ce64401e63dcffd233b258b37ea2 Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Wed, 11 Dec 2024 16:18:10 +0900 Subject: [PATCH 28/29] rpm: improve process timing for safety (#764) Points * FROM-package just leaves tmp files if it supports the features. * TO-package trigger the features if there are those tmp files. * Thus, can ensure that both FROM and TO support the feature. * Make installing plugin and restarting the same condition. * Disable `%systemd_postun_with_restart` completely to align specifications with DEB. Before 1. to-pre(2): Collect plugin-list. 2. Install TO-package 3. to-post(2): Install plugin. 4. from-preun(1): Do nothing. 5. Uninstall FROM-package 6. from-postun(1): Restart if need. After 1. to-pre(2): Collect plugin-list. 2. Install TO-package 3. to-post(2): Do nothing. 4. from-preun(1): * Check auto or not. * Leave plugin-install flag and pid if need. 5. Uninstall FROM-package 6. from-postun(1): Disable `%systemd_postun_with_restart`. 7. to-posttrans: Install plugin and restart if need. Signed-off-by: Daijiro Fukuda --- .github/workflows/yum.yml | 18 ++- .../apt/systemd-test/downgrade-to-v5-lts.sh | 1 + fluent-package/yum/fluent-package.spec.in | 106 ++++++++++-------- .../yum/systemd-test/downgrade-to-v5-lts.sh | 25 ++++- .../update-to-next-major-version.sh | 7 +- 5 files changed, 101 insertions(+), 56 deletions(-) diff --git a/.github/workflows/yum.yml b/.github/workflows/yum.yml index f3a4843ea..c7daeb765 100644 --- a/.github/workflows/yum.yml +++ b/.github/workflows/yum.yml @@ -153,9 +153,12 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-with-auto-and-manual.sh" - - "update-to-next-major-version.sh auto" - - "update-to-next-major-version.sh manual" - - "update-to-next-major-version.sh etc" + - "update-to-next-major-version.sh auto active" + - "update-to-next-major-version.sh auto inactive" + - "update-to-next-major-version.sh manual active" + - "update-to-next-major-version.sh manual inactive" + - "update-to-next-major-version.sh etc active" + - "update-to-next-major-version.sh etc inactive" - "update-without-data-lost.sh v5 v6" - "update-without-data-lost.sh v6 v5" include: @@ -229,9 +232,12 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-with-auto-and-manual.sh" - - "update-to-next-major-version.sh auto" - - "update-to-next-major-version.sh manual" - - "update-to-next-major-version.sh etc" + - "update-to-next-major-version.sh auto active" + - "update-to-next-major-version.sh auto inactive" + - "update-to-next-major-version.sh manual active" + - "update-to-next-major-version.sh manual inactive" + - "update-to-next-major-version.sh etc active" + - "update-to-next-major-version.sh etc inactive" - "update-without-data-lost.sh v5 v6" - "update-without-data-lost.sh v6 v5" include: diff --git a/fluent-package/apt/systemd-test/downgrade-to-v5-lts.sh b/fluent-package/apt/systemd-test/downgrade-to-v5-lts.sh index 50ac15e50..2858daa2e 100755 --- a/fluent-package/apt/systemd-test/downgrade-to-v5-lts.sh +++ b/fluent-package/apt/systemd-test/downgrade-to-v5-lts.sh @@ -25,4 +25,5 @@ systemctl status --no-pager fluentd systemctl status --no-pager td-agent # Fluentd should be restarted. +# NOTE: Unlike RPM, the restart behavior depends on TO-side. So, it restarts. test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index c3b50eb8d..ba01eba29 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -33,6 +33,8 @@ %define v4migration_old_rotate_config_saved /tmp/@PACKAGE_DIR@/.old_rotate_config %define v4migration_enabled_service /tmp/@PACKAGE_DIR@/.v4migration_enabled_service %define local_base_plugins /tmp/@PACKAGE_DIR@/.local_base_plugins +%define install_plugins /tmp/@PACKAGE_DIR@/.install_plugins +%define pid_for_auto_restart /tmp/@PACKAGE_DIR@/.pid_for_auto_restart # Omit the brp-python-bytecompile automagic because post hook for ffi fails on AmazonLinux 2. %if %{_amazon_ver} == 2 @@ -160,6 +162,14 @@ mkdir -p %{buildroot}%{_sysconfdir}/@PACKAGE_DIR@/plugin mkdir -p %{buildroot}/tmp/@PACKAGE_DIR@ %pre +# Make sure the previous tmp files for auto restart does not remain. +# Note: +# %preun (FROM-side) can create these files, but they will be removed in %posttrans (TO-side). +# This means that these files may not be removed depending on the version of TO-side. +# In the future, want to figure out a more secure way to manage tmp files... +rm -f %{install_plugins} +rm -f %{pid_for_auto_restart} + if ! getent group @COMPAT_SERVICE_NAME@ >/dev/null; then if ! getent group @SERVICE_NAME@ >/dev/null; then /usr/sbin/groupadd --system @SERVICE_NAME@ @@ -188,16 +198,35 @@ else fi fi if [ $1 -eq 2 ]; then - . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ - echo "pre FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" - if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = auto ]; then - # collect installed gems during upgrading + # Collect plugin-list. + # Note: + # This should be done in %preun(1) of FROM-side, but we have no choice but to do this here. + # %preun(1) of FROM-side is executed after TO-side installs the files and replaces embedded Ruby. + # So, this needs to be done before it. + if [ -e /usr/sbin/fluent-gem ]; then /usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose > %{local_base_plugins} fi fi %preun %systemd_preun @SERVICE_NAME@.service +if [ $1 -eq 1 ]; then + # systemctl ... --property=MainPID --value is available since systemd 230 or later. + # thus for amazonlinux:2, it can not be used. + pid="$(systemctl show "@SERVICE_NAME@" --property=MainPID | cut -d'=' -f2)" + if [ "$pid" -eq 0 ]; then + echo "Do not use auto restart because the service is not active" + else + . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ + echo "FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" + if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = auto ]; then + # Present that FROM-side wants auto installing plugins and restarting. + # Note: Wants to collect plugin-list here, but we need to do it in %pre (see comments in %pre). + touch %{install_plugins} + echo "$pid" > %{pid_for_auto_restart} + fi + fi +fi %post %systemd_post @SERVICE_NAME@.service @@ -291,51 +320,9 @@ if [ -f "%{_sysconfdir}/prelink.conf" ]; then %{__sed} -i"" %{_sysconfdir}/prelink.conf -e "/\/opt\/td-agent\/bin\/ruby/d" fi fi -if [ $1 -eq 2 ]; then - # install missing plugins during upgrading package - if [ -f %{local_base_plugins} ]; then - local_current_plugins=$(/usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose) - if ! grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins}; then - echo "No missing plugins to install" - else - if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then - echo "No network connectivity..." - else - grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins} | while read missing_gem - do - if ! /usr/sbin/fluent-gem install --no-document $missing_gem; then - echo "Can't install missing plugin automatically: please install $missing_gem manually." - fi - done - fi - fi - rm -f %{local_base_plugins} - fi -fi %postun -if [ $1 -eq 1 ]; then - # Control service during upgrading - . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ - echo "postun FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" - if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "auto" ]; then - # systemctl ... --property=MainPID --value is available since systemd 230 or later. - # thus for amazonlinux:2, it can not be used. - pid=$(systemctl show fluentd --property=MainPID | cut -d'=' -f2) - if [ $pid -gt 0 ]; then - echo "Kick auto service upgrade mode to MainPID:$pid" - kill -USR2 $pid - else - # no running fluentd service - echo "Suppress auto service upgrade mode to MainPID:$pid" - fi - elif [ "$FLUENT_PACKAGE_SERVICE_RESTART" = "manual" ]; then - echo "No need to restart service in manual mode..." - else - # no support for upgrading without downtime - %systemd_postun_with_restart @SERVICE_NAME@.service - fi -fi +# Disable systemd_postun_with_restart to manage restart on the package side. if [ $1 -eq 0 ]; then # Uninstall # Without this uninstall conditional guard block ($1 -eq 0), symlink @@ -400,6 +387,31 @@ if [ -f %{v4migration} ]; then rm -f %{v4migration_with_restart} fi fi +if [ -f %{install_plugins} ] && [ -f %{local_base_plugins} ]; then + local_current_plugins=$(/usr/sbin/fluent-gem list '^fluent-plugin-' --no-versions --no-verbose) + if ! grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins}; then + echo "No missing plugins to install" + else + if ! curl --fail --silent -O https://rubygems.org/specs.4.8.gz; then + echo "No network connectivity..." + else + grep --fixed-strings --line-regexp --invert-match "$local_current_plugins" %{local_base_plugins} | while read missing_gem + do + if ! /usr/sbin/fluent-gem install --no-document $missing_gem; then + echo "Can't install missing plugin automatically: please install $missing_gem manually." + fi + done + fi + fi +fi +rm -f %{install_plugins} +rm -f %{local_base_plugins} +if [ -f %{pid_for_auto_restart} ]; then + pid=$(cat %{pid_for_auto_restart}) + echo "Kick auto restart to MainPID:$pid" + kill -USR2 $pid + rm -f %{pid_for_auto_restart} +fi %files %doc README.md diff --git a/fluent-package/yum/systemd-test/downgrade-to-v5-lts.sh b/fluent-package/yum/systemd-test/downgrade-to-v5-lts.sh index a0dd8af01..8c1fa7a50 100755 --- a/fluent-package/yum/systemd-test/downgrade-to-v5-lts.sh +++ b/fluent-package/yum/systemd-test/downgrade-to-v5-lts.sh @@ -27,6 +27,10 @@ sudo $DNF remove -y fluent-package sudo $DNF install -y \ /host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm +# Customize the env file to prevent replacing by downgrade. +# Need this to test the case where some tmp files is left. +echo "FOO=foo" >> /etc/sysconfig/fluentd + sudo systemctl enable --now fluentd systemctl status --no-pager fluentd systemctl status --no-pager td-agent @@ -42,5 +46,22 @@ systemctl is-enabled fluentd systemctl status --no-pager fluentd systemctl status --no-pager td-agent -# Fluentd should be restarted. -test $main_pid -ne $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) +# Fluentd should NOT be restarted. +# NOTE: Unlike DEB, the restart behavior depends on FROM-side. So, it does not restart. +# (it should restarts only when triggering zerodowntime-restart). +test $main_pid -eq $(eval $(systemctl show fluentd --property=MainPID) && echo $MainPID) + +# === Test: Remained tmp files should not affect to next upgrade === +# (This happens when env file was customized but the FLUENT_PACKAGE_SERVICE_RESTART was still `auto`) + +# Some tmp files remains, though it is not happy. +test -e /tmp/fluent/.install_plugins +test -e /tmp/fluent/.pid_for_auto_restart + +sudo $DNF install -y \ + /host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm | tee upgrade.log + +# zerodowntime-restart should NOT be triggered. +(! grep "Kick auto restart" upgrade.log) + +# ====== diff --git a/fluent-package/yum/systemd-test/update-to-next-major-version.sh b/fluent-package/yum/systemd-test/update-to-next-major-version.sh index 4aa1131f3..26390f41e 100755 --- a/fluent-package/yum/systemd-test/update-to-next-major-version.sh +++ b/fluent-package/yum/systemd-test/update-to-next-major-version.sh @@ -5,11 +5,16 @@ set -exu . $(dirname $0)/commonvar.sh service_restart=$1 +status_before_update=$2 # active / inactive # Install the current package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-*.rpm" sudo $DNF install -y $package +if [ "$status_before_update" = active ]; then + sudo systemctl start fluentd +fi + # Set FLUENT_PACKAGE_SERVICE_RESTART sed -i "s/=auto/=$service_restart/" /etc/sysconfig/fluentd @@ -22,7 +27,7 @@ package="/host/v6-test/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/f sudo $DNF install -y $package # Test: Check whether plugin/gem were installed during upgrading -if [ "$service_restart" = auto ]; then +if [ "$service_restart" = auto ] && [ "$status_before_update" = active ]; then # plugin gem should be installed automatically /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat # Non fluent-plugin- prefix gem should not be installed automatically From 33c1c1c9b2c68243094e0d5b18556b0ed30087f6 Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Wed, 11 Dec 2024 19:00:59 +0900 Subject: [PATCH 29/29] FLUENT_PACKAGE_SERVICE_RESTART: make empty or other values as auto (#767) Signed-off-by: Kentaro Hayashi --- .github/workflows/apt.yml | 9 ++++++--- .../apt/systemd-test/update-to-next-major-version.sh | 7 ++++++- .../templates/package-scripts/fluent-package/deb/prerm | 2 +- fluent-package/yum/fluent-package.spec.in | 2 +- .../yum/systemd-test/update-to-next-major-version.sh | 2 +- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/apt.yml b/.github/workflows/apt.yml index 1c3da5ae1..b7e57971c 100644 --- a/.github/workflows/apt.yml +++ b/.github/workflows/apt.yml @@ -178,9 +178,12 @@ jobs: - "update-to-next-version-service-status.sh disabled active" - "update-to-next-version-service-status.sh disabled inactive" - "update-to-next-version-with-auto-and-manual.sh" - - "update-to-next-major-version.sh auto" - - "update-to-next-major-version.sh manual" - - "update-to-next-major-version.sh etc" + - "update-to-next-major-version.sh auto active" + - "update-to-next-major-version.sh auto inactive" + - "update-to-next-major-version.sh manual active" + - "update-to-next-major-version.sh manual inactive" + - "update-to-next-major-version.sh etc active" + - "update-to-next-major-version.sh etc inactive" - "update-without-data-lost.sh v5 v6" - "update-without-data-lost.sh v6 v5" include: diff --git a/fluent-package/apt/systemd-test/update-to-next-major-version.sh b/fluent-package/apt/systemd-test/update-to-next-major-version.sh index 9add0d328..cb6fb0f9d 100755 --- a/fluent-package/apt/systemd-test/update-to-next-major-version.sh +++ b/fluent-package/apt/systemd-test/update-to-next-major-version.sh @@ -5,11 +5,16 @@ set -exu . $(dirname $0)/../commonvar.sh service_restart=$1 +status_before_update=$2 # active / inactive # Install the current sudo apt install -V -y \ /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb +if [ "$status_before_update" = inactive ]; then + sudo systemctl stop fluentd +fi + # Set FLUENT_PACKAGE_SERVICE_RESTART sed -i "s/=auto/=$service_restart/" /etc/default/fluentd @@ -35,7 +40,7 @@ if dpkg-query --show --showformat='${Version}' needrestart ; then fi # Test: Check whether plugin/gem were installed during upgrading -if [ "$service_restart" = auto ]; then +if [ "$service_restart" != manual ] && [ "$status_before_update" = active ]; then # plugin gem should be installed automatically /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat # Non fluent-plugin- prefix gem should not be installed automatically diff --git a/fluent-package/templates/package-scripts/fluent-package/deb/prerm b/fluent-package/templates/package-scripts/fluent-package/deb/prerm index 5e516d762..bd1c662bf 100755 --- a/fluent-package/templates/package-scripts/fluent-package/deb/prerm +++ b/fluent-package/templates/package-scripts/fluent-package/deb/prerm @@ -40,7 +40,7 @@ leave_info_for_auto_restart_if_need() { . "/etc/default/<%= service_name %>" echo "FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" - if [ "$FLUENT_PACKAGE_SERVICE_RESTART" != auto ]; then + if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = manual ]; then return fi diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index ba01eba29..a204f9cdf 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -219,7 +219,7 @@ if [ $1 -eq 1 ]; then else . %{_sysconfdir}/sysconfig/@SERVICE_NAME@ echo "FLUENT_PACKAGE_SERVICE_RESTART: $FLUENT_PACKAGE_SERVICE_RESTART" - if [ "$FLUENT_PACKAGE_SERVICE_RESTART" = auto ]; then + if [ "$FLUENT_PACKAGE_SERVICE_RESTART" != manual ]; then # Present that FROM-side wants auto installing plugins and restarting. # Note: Wants to collect plugin-list here, but we need to do it in %pre (see comments in %pre). touch %{install_plugins} diff --git a/fluent-package/yum/systemd-test/update-to-next-major-version.sh b/fluent-package/yum/systemd-test/update-to-next-major-version.sh index 26390f41e..f2a888de1 100755 --- a/fluent-package/yum/systemd-test/update-to-next-major-version.sh +++ b/fluent-package/yum/systemd-test/update-to-next-major-version.sh @@ -27,7 +27,7 @@ package="/host/v6-test/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/f sudo $DNF install -y $package # Test: Check whether plugin/gem were installed during upgrading -if [ "$service_restart" = auto ] && [ "$status_before_update" = active ]; then +if [ "$service_restart" != manual ] && [ "$status_before_update" = active ]; then # plugin gem should be installed automatically /opt/fluent/bin/fluent-gem list | grep fluent-plugin-concat # Non fluent-plugin- prefix gem should not be installed automatically