Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpm: take over enabled state of systemd service from v4 #613

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
kenhys marked this conversation as resolved.
Show resolved Hide resolved
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
kenhys marked this conversation as resolved.
Show resolved Hide resolved
systemctl status --no-pager td-agent

Expand Down
2 changes: 2 additions & 0 deletions fluent-package/yum/systemd-test/update-to-next-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ next_package=$(find rpmbuild -name "*.rpm")

# Install the dummy package of the next version
sudo $DNF install -y ./$next_package
# Test: take over enabled state
systemctl is-enabled fluentd
sudo systemctl enable --now fluentd
kenhys marked this conversation as resolved.
Show resolved Hide resolved
systemctl status --no-pager fluentd

Expand Down