Skip to content

Commit

Permalink
rpm: take over enabled state of systemd service from v4
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.

Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
  • Loading branch information
kenhys committed Feb 7, 2024
1 parent 7e637b3 commit caca57b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 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@/@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
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
3 changes: 3 additions & 0 deletions fluent-package/yum/systemd-test/update-from-v4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ 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

# Test: take over enabled state
systemctl is-enabled fluentd

sudo systemctl enable --now fluentd
systemctl status --no-pager td-agent

Expand Down

0 comments on commit caca57b

Please sign in to comment.