1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

rpm: when disabling a unit, do not complain if systemd is not running

$ sudo dnf remove --installroot=/var/tmp/img1 systemd-networkd
...
  Running scriptlet: systemd-networkd-248~rc4-4.fc32.x86_64      1/1
Removed /etc/systemd/system/multi-user.target.wants/systemd-networkd.service.
Removed /etc/systemd/system/sockets.target.wants/systemd-networkd.socket.
Removed /etc/systemd/system/dbus-org.freedesktop.network1.service.
Removed /etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service.
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

(Another option would be make --now do nothing if systemd is not running.
But I think that's not too good. 'disable --now' doing nothing would be OK,
since if systemd is not running, the service is not running either, so we are
in the desired state. But that argument doesn't work for 'enable --now'. And
accepting 'disable --now' but not 'enable --now' seems overly complex. So I
think it is better to make the scriptlet handle this case explicitly.)

Also, let's reindent the file to 4 spaces. Very deeply nested scriptlets are
harder to read, and the triggers file is indented to 4 spaces already.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-03-26 17:09:13 +01:00
parent a83ddc08d6
commit a59eb7d78f

View File

@ -47,8 +47,8 @@ OrderWithRequires(postun): systemd \
%systemd_post() \
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_post}} \
if [ $1 -eq 1 ] && [ -x @bindir@/systemctl ]; then \
# Initial installation \
@bindir@/systemctl --no-reload preset %{?*} || : \
# Initial installation \
@bindir@/systemctl --no-reload preset %{?*} || : \
fi \
%{nil}
@ -57,16 +57,20 @@ fi \
%systemd_preun() \
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_preun}} \
if [ $1 -eq 0 ] && [ -x @bindir@/systemctl ]; then \
# Package removal, not upgrade \
@bindir@/systemctl --no-reload disable --now %{?*} || : \
# Package removal, not upgrade \
if [ -d /run/systemd/system ]; then \
@bindir@/systemctl --no-reload disable --now %{?*} || : \
else \
@bindir@/systemctl --no-reload disable %{?*} || : \
fi \
fi \
%{nil}
%systemd_user_preun() \
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_user_preun}} \
if [ $1 -eq 0 ] && [ -x @bindir@/systemctl ]; then \
# Package removal, not upgrade \
@bindir@/systemctl --global disable %{?*} || : \
# Package removal, not upgrade \
@bindir@/systemctl --global disable %{?*} || : \
fi \
%{nil}
@ -81,10 +85,10 @@ fi \
%systemd_postun_with_restart() \
%{expand:%%{?__systemd_someargs_%#:%%__systemd_someargs_%# systemd_postun_with_restart}} \
if [ $1 -ge 1 ] && [ -x @bindir@/systemctl ]; then \
# Package upgrade, not uninstall \
for unit in %{?*}; do \
@bindir@/systemctl set-property $unit Markers=+needs-restart || : \
done \
# Package upgrade, not uninstall \
for unit in %{?*}; do \
@bindir@/systemctl set-property $unit Markers=+needs-restart || : \
done \
fi \
%{nil}