Skip to content

Commit

Permalink
rpm: take over enabled state of systemd service from v4 (#613)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kenhys authored Feb 19, 2024
1 parent 7e637b3 commit eada0a7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
12 changes: 12 additions & 0 deletions fluent-package/yum/fluent-package.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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}/.*
Expand Down Expand Up @@ -207,6 +208,11 @@ if [ $1 -eq 1 ]; then
ln -sf /etc/@PACKAGE_DIR@/@[email protected] /etc/@PACKAGE_DIR@/@[email protected]
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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion fluent-package/yum/systemd-test/update-from-v4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion fluent-package/yum/systemd-test/update-to-next-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eada0a7

Please sign in to comment.