From 182857a71cf25e308cb29ced3b73de83304a5374 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Wed, 4 Dec 2024 19:07:16 +0900 Subject: [PATCH] deb: suppress service restart by needrestart Since Ubuntu 24.04, needrestart package kicks service restart out of package maintainer scripts. Take back fluentd service under control for us, it had better to suppress it. NOTE: It seems that needrestart package is available from EPEL 8/9, but it is broken for a long time, so just ignore it. Needrestart package missing dependency https://bugzilla.redhat.com/show_bug.cgi?id=2154293 Signed-off-by: Kentaro Hayashi Co-authored-by: Shizuo Fujita --- fluent-package/Rakefile | 19 +++++++++++++++---- .../apt/systemd-test/update-from-v4.sh | 14 +++++++++++++- .../update-to-next-version-service-status.sh | 15 ++++++++++++++- fluent-package/debian/fluent-package.install | 1 + .../needrestart/conf.d/50-fluent-package.conf | 6 ++++++ 5 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 fluent-package/templates/etc/needrestart/conf.d/50-fluent-package.conf diff --git a/fluent-package/Rakefile b/fluent-package/Rakefile index bc9ac4086..3d1f8c579 100755 --- a/fluent-package/Rakefile +++ b/fluent-package/Rakefile @@ -1158,10 +1158,21 @@ class BuildTask fluentd_conf = "etc/#{PACKAGE_DIR}/#{SERVICE_NAME}.conf" fluentd_conf_default = "opt/#{PACKAGE_DIR}/share/#{SERVICE_NAME}.conf" configs = [fluentd_conf] - configs.concat([ - "etc/logrotate.d/#{SERVICE_NAME}", - fluentd_conf_default, - ]) unless windows? || macos? + unless windows? || macos? + configs.concat([ + "etc/logrotate.d/#{SERVICE_NAME}", + fluentd_conf_default, + ]) + File.readlines("/etc/os-release").each do |line| + if line.include?("ID=") + distribution = line.split(/=/).last.chomp + if ["debian", "ubuntu"].include?(distribution) + puts "Suppress needrestart on #{distribution}" + configs.concat(["etc/needrestart/conf.d/50-fluent-package.conf"]) + end + end + end + end configs.each do |config| src = if config == fluentd_conf_default diff --git a/fluent-package/apt/systemd-test/update-from-v4.sh b/fluent-package/apt/systemd-test/update-from-v4.sh index a82658d74..c2c0f8f27 100755 --- a/fluent-package/apt/systemd-test/update-from-v4.sh +++ b/fluent-package/apt/systemd-test/update-from-v4.sh @@ -23,7 +23,19 @@ case $1 in local) sudo apt install -V -y \ /host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb \ - /host/${distribution}/pool/${code_name}/${channel}/*/*/td-agent_*_all.deb + /host/${distribution}/pool/${code_name}/${channel}/*/*/td-agent_*_all.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 ;; v5) curl --fail --silent --show-error --location https://toolbelt.treasuredata.com/sh/install-${distribution}-${code_name}-fluent-package5.sh | sh 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 110fcf949..502896283 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 @@ -33,7 +33,20 @@ fi main_pid=$(systemctl show --value --property=MainPID fluentd) # Install the dummy package -sudo apt install -V -y ./next_version.deb +sudo apt install -V -y ./next_version.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 # The service should take over the state if [ "$enabled_before_update" = enabled ]; then diff --git a/fluent-package/debian/fluent-package.install b/fluent-package/debian/fluent-package.install index 76c8235cf..bdfe5fbb7 100644 --- a/fluent-package/debian/fluent-package.install +++ b/fluent-package/debian/fluent-package.install @@ -5,4 +5,5 @@ usr/lib/tmpfiles.d/* etc/logrotate.d/* etc/fluent/* etc/default/* +etc/needrestart/conf.d/* lib/systemd/system/* diff --git a/fluent-package/templates/etc/needrestart/conf.d/50-fluent-package.conf b/fluent-package/templates/etc/needrestart/conf.d/50-fluent-package.conf new file mode 100644 index 000000000..ddb1971c7 --- /dev/null +++ b/fluent-package/templates/etc/needrestart/conf.d/50-fluent-package.conf @@ -0,0 +1,6 @@ +# Configuration for needrestart + +# Always suppress restarting by needrestart. +$nrconf{blacklist_rc} = [ + qr(^fluentd\.service$) +];