From eada0a73c62b10e6cf71300fb7ff502842f5495a Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Mon, 19 Feb 2024 14:50:20 +0900 Subject: [PATCH] rpm: take over enabled state of systemd service from v4 (#613) In the previous versions, the enabled service status of td-agent was not migrated. This commit try to take over existing td-agent service status. Note that if systemctl enable fluentd is executed in %post section, it was reverted in td-agent's %preun scriptlet. So it is enabled in %posttrans explicitly. Closes: #610 --- fluent-package/yum/fluent-package.spec.in | 12 ++++++++++++ fluent-package/yum/systemd-test/update-from-v4.sh | 5 ++++- ...te-to-next-version-with-backward-compat-for-v4.sh | 6 +++++- .../yum/systemd-test/update-to-next-version.sh | 3 ++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/fluent-package/yum/fluent-package.spec.in b/fluent-package/yum/fluent-package.spec.in index ef5e91af4..e3379af74 100644 --- a/fluent-package/yum/fluent-package.spec.in +++ b/fluent-package/yum/fluent-package.spec.in @@ -31,6 +31,7 @@ %define v4migration /tmp/@PACKAGE_DIR@/.v4migration %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 %global __provides_exclude_from ^/opt/%{name}/.*\\.so.* %global __requires_exclude libjemalloc.*|libruby.*|/opt/%{name}/.* @@ -207,6 +208,11 @@ if [ $1 -eq 1 ]; then ln -sf /etc/@PACKAGE_DIR@/@COMPAT_SERVICE_NAME@.conf /etc/@PACKAGE_DIR@/@SERVICE_NAME@.conf fi fi + if systemctl is-enabled @COMPAT_SERVICE_NAME@; then + # It is not enough to systemctl enable fluentd here for taking over enabled service status + # because td-agent %preun disables td-agent so fluentd is also disabled. + touch %{v4migration_enabled_service} + fi if systemctl is-active @COMPAT_SERVICE_NAME@; then if getent passwd @COMPAT_SERVICE_NAME@ >/dev/null; then if ! getent passwd @SERVICE_NAME@ >/dev/null; then @@ -314,6 +320,12 @@ if [ -f %{v4migration} ]; then echo "Restores logrotate config from backup" mv -f %{v4migration_old_rotate_config_saved} /etc/logrotate.d/@COMPAT_SERVICE_NAME@ fi + if [ -f %{v4migration_enabled_service} ]; then + # Explicitly enable service here not to be disabled during td-agent's %preun scriptlet. + echo "@COMPAT_SERVICE_NAME@ was enabled. Take over enabled service status ..." + systemctl enable @SERVICE_NAME@ + rm -f %{v4migration_enabled_service} + fi rm -f %{v4migration} if [ -f %{v4migration_with_restart} ]; then # When upgrading from v4, td-agent.service will be removed diff --git a/fluent-package/yum/systemd-test/update-from-v4.sh b/fluent-package/yum/systemd-test/update-from-v4.sh index b63807722..acdc7d027 100755 --- a/fluent-package/yum/systemd-test/update-from-v4.sh +++ b/fluent-package/yum/systemd-test/update-from-v4.sh @@ -38,9 +38,12 @@ systemctl status --no-pager td-agent 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 # Migration process starts the service automatically -sudo systemctl enable --now fluentd +sudo systemctl enable fluentd # Enable the unit name alias systemctl status --no-pager td-agent # Test: config migration diff --git a/fluent-package/yum/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh b/fluent-package/yum/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh index f1b3d342e..a077a9e0b 100755 --- a/fluent-package/yum/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh +++ b/fluent-package/yum/systemd-test/update-to-next-version-with-backward-compat-for-v4.sh @@ -38,7 +38,11 @@ systemctl status --no-pager td-agent package="/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm" sudo $DNF install -y $package systemctl status --no-pager fluentd # Migration process starts the service automatically -sudo systemctl enable --now fluentd + +# Test: take over enabled state +systemctl is-enabled fluentd + +sudo systemctl enable fluentd # Enable the unit name alias systemctl status --no-pager td-agent # Make a dummy pacakge for the next version diff --git a/fluent-package/yum/systemd-test/update-to-next-version.sh b/fluent-package/yum/systemd-test/update-to-next-version.sh index aa42de076..c661384e8 100755 --- a/fluent-package/yum/systemd-test/update-to-next-version.sh +++ b/fluent-package/yum/systemd-test/update-to-next-version.sh @@ -40,7 +40,8 @@ next_package=$(find rpmbuild -name "*.rpm") # Install the dummy package of the next version sudo $DNF install -y ./$next_package -sudo systemctl enable --now fluentd +# Test: take over enabled state +systemctl is-enabled fluentd systemctl status --no-pager fluentd # Test: migration process from v4 must not be done