From c95c14ba25cc3bbbffc7bf10f1a223f3af922f6a Mon Sep 17 00:00:00 2001 From: Boris Ranto Date: Fri, 2 Oct 2015 09:56:01 +0200 Subject: [PATCH] ceph.spec.in: Do not always restart the daemons on upgrades This patch minimizes the amount of daemon stop/start procedures when upgrading ceph-selinux package. With this patch, the daemons get restarted only if SELinux is enabled and the SELinux policy version changed in the meantime. Fixes: #13061 Signed-off-by: Boris Ranto --- ceph.spec.in | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/ceph.spec.in b/ceph.spec.in index 47f4e09a6e3e1..239a0fa7da09e 100644 --- a/ceph.spec.in +++ b/ceph.spec.in @@ -1126,6 +1126,25 @@ ln -sf %{_libdir}/librbd.so.1 /usr/lib64/qemu/librbd.so.1 %{_mandir}/man8/ceph_selinux.8.* %post selinux +# Install the policy +OLD_POLVER=$(%{_sbindir}/semodule -l | grep -P '^ceph[\t ]' | awk '{print $2}') +%{_sbindir}/semodule -n -i %{_datadir}/selinux/packages/ceph.pp +NEW_POLVER=$(%{_sbindir}/semodule -l | grep -P '^ceph[\t ]' | awk '{print $2}') + +# Load the policy if SELinux is enabled +if %{_sbindir}/selinuxenabled; then + %{_sbindir}/load_policy +else + # Do not relabel if selinux is not enabled + exit 0 +fi + +if test "$OLD_POLVER" == "$NEW_POLVER"; then + # Do not relabel if policy version did not change + exit 0 +fi + +# Check whether the daemons are running %if 0%{?_with_systemd} /usr/bin/systemctl status ceph.target > /dev/null 2>&1 %else @@ -1133,6 +1152,7 @@ ln -sf %{_libdir}/librbd.so.1 /usr/lib64/qemu/librbd.so.1 %endif STATUS=$? +# Stop the daemons if they were running if test $STATUS -eq 0; then %if 0%{?_with_systemd} /usr/bin/systemctl stop ceph.target > /dev/null 2>&1 @@ -1141,17 +1161,10 @@ if test $STATUS -eq 0; then %endif fi -OLD_POLVER=$(%{_sbindir}/semodule -l | grep -P '^ceph[\t ]' | awk '{print $2}') -%{_sbindir}/semodule -n -i %{_datadir}/selinux/packages/ceph.pp -NEW_POLVER=$(%{_sbindir}/semodule -l | grep -P '^ceph[\t ]' | awk '{print $2}') -if %{_sbindir}/selinuxenabled; then - %{_sbindir}/load_policy - if test "$OLD_POLVER" != "$NEW_POLVER"; then - %relabel_files - fi -fi +# Now, relabel the files +%relabel_files -# Start iff it was started before +# Start the daemons iff they were running before if test $STATUS -eq 0; then %if 0%{?_with_systemd} /usr/bin/systemctl start ceph.target > /dev/null 2>&1 || : -- 2.39.5