spec: Only run worker preun if systemd is running

Before, when systemd was not present (for instance in a container), the
preun script would error out.

This checks if systemd is present and running in the same way the
systemd rpm macros do.

Fixes #1915
This commit is contained in:
sanne 2021-10-18 11:11:36 +02:00 committed by Tom Gundersen
parent 03074303cc
commit 117886a75f

View file

@ -349,10 +349,11 @@ The worker for osbuild-composer
# systemd_preun uses systemctl disable --now which doesn't work well with template services.
# See https://github.com/systemd/systemd/issues/15620
# The following lines mimicks its behaviour by running two commands:
# disable and stop all the worker services
systemctl --no-reload disable osbuild-worker@.service osbuild-remote-worker@.service
systemctl stop "osbuild-worker@*.service" "osbuild-remote-worker@*.service"
if [ -d /run/systemd/system ]; then
# disable and stop all the worker services
systemctl --no-reload disable osbuild-worker@.service osbuild-remote-worker@.service
systemctl stop "osbuild-worker@*.service" "osbuild-remote-worker@*.service"
fi
%postun worker
# restart all the worker services