Bug 1986258 - regression in systemd_postun_with_restart scriptlet on Fedora 34
Summary: regression in systemd_postun_with_restart scriptlet on Fedora 34
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: systemd
Version: 34
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: systemd-maint
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-07-27 05:37 UTC by Dan Čermák
Modified: 2021-08-08 01:04 UTC (History)
15 users (show)

Fixed In Version: systemd-248.7-1.fc34
Clone Of:
Environment:
Last Closed: 2021-08-08 01:04:09 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Dan Čermák 2021-07-27 05:37:26 UTC
Description of problem:
When running dnf upgrade, one of the scriptlets results in the following warning being printed to stdout:

Glob pattern passed, but globs are not supported for this.
Invalid unit name "syncthing@*.service" escaped as "syncthing@\x2a.service".


Version-Release number of selected component (if applicable):
syncthing 1.18.0

Steps to Reproduce:
1. dnf upgrade from a syncthing <= 1.18.0

Actual results:
Warning is printed to stdout

Expected results:
No warning should appear

Comment 1 Kim Bisgaard 2021-07-27 07:53:50 UTC
This command seems to do what is intended:
systemctl --plain --quiet --type=service --state=running  list-units|awk '/syncthing@/ {system("systemctl restart "$1)}'

Comment 2 Fabio Valentini 2021-07-27 15:19:35 UTC
Yeah. I know about this, but I'm not sure what the correct syntax for this scriptlet would be.
BTW, the glob has never worked, it's just that systemd on Fedora 34+ warns about it now.
I'll ask on the mailing list how to handle this correctly.

Comment 3 Zbigniew Jędrzejewski-Szmek 2021-07-28 11:02:00 UTC
This is an omission from my side. The easiest solution (longer-term) is to allow such globs
in systemd. I filed a simple patch to do this [1]. When it goes through, I'll push it to
F34+ where the new scriptlet is used, and then it should be enough to rebuild this package.

[1] https://github.com/systemd/systemd/pull/20334

Comment 4 Zbigniew Jędrzejewski-Szmek 2021-07-28 11:02:41 UTC
Actually… we don't even need to rebuild syncthing, it should just work when the new
systemd is installed.

Comment 5 Fabio Valentini 2021-07-29 11:22:21 UTC
I think you misunderstood me. The scriptlet warning about the glob does not come from a user unit (those are not templates), but a *system* unit, which are instantiated by username.


%post
%systemd_post 'syncthing@.service'
%systemd_user_post syncthing.service

%preun
%systemd_preun 'syncthing@*.service'
%systemd_user_preun syncthing.service

%postun
%systemd_postun_with_restart 'syncthing@*.service'
%systemd_user_postun_with_restart syncthing.service


The *user* variants are fine.
But I need to modify one of the calls for the instantiated *system* units to account for the fact they come from templates ...
And I don't know how to do that, since I do not understand the underlying systemctl commands.

Comment 6 Fabio Valentini 2021-08-06 09:44:16 UTC
Ok, after digging into the definition of the systemd scriptlets:


$ rpm -E "%systemd_post syncthing@*.service"

if [ $1 -eq 1 ] && [ -x /usr/bin/systemctl ]; then 
    # Initial installation 
    /usr/bin/systemctl --no-reload preset syncthing@*.service || : 
fi 

This is obviously nonsense. Applying presets to instantiated templates cannot work (which values of @i are supposed to be injected?)
So, can I just drop the %systemd_post scriptlet in this case?
The systemd service is not enabled by default, so users need to create an instantiated service anyway.



$ rpm -E "%systemd_postun_with_restart syncthing@*.service"
 
if [ $1 -ge 1 ] && [ -x /usr/bin/systemctl ]; then 
    # Package upgrade, not uninstall 
    for unit in syncthing@*.service; do 
         /usr/bin/systemctl set-property $unit Markers=+needs-restart || : 
    done 
fi 

The "systemctl set-property" command does not support globs, and hence does not support services that are instantiated from templates.
I'm pretty sure that at least the %systemd_postun_with_restart scriptlet used to work in previous releases.
And starting up my Fedora 33 VM, I see now why this is a new problem with Fedora 34, because in Fedora 33, this scriptlet does something different:

$ rpm -E "%systemd_postun_with_restart syncthing@*.service" 

 
if [ $1 -ge 1 ] && [ -x /usr/bin/systemctl ]; then 
        # Package upgrade, not uninstall 
        /usr/bin/systemctl try-restart syncthing@*.service || : 
fi 

And the "systemctl try-restart" command supports globs, while the "systemctl set-property" command does not.
So this is really a regression in the systemd RPM scriptlets between Fedora 33 and 34.

Comment 7 Zbigniew Jędrzejewski-Szmek 2021-08-06 10:02:33 UTC
(In reply to Fabio Valentini from comment #6)
> Ok, after digging into the definition of the systemd scriptlets:
> 
> 
> $ rpm -E "%systemd_post syncthing@*.service"
> 
> if [ $1 -eq 1 ] && [ -x /usr/bin/systemctl ]; then 
>     # Initial installation 
>     /usr/bin/systemctl --no-reload preset syncthing@*.service || : 
> fi 
> 
> This is obviously nonsense. Applying presets to instantiated templates
> cannot work (which values of @i are supposed to be injected?)
> So, can I just drop the %systemd_post scriptlet in this case?
> The systemd service is not enabled by default, so users need to create an
> instantiated service anyway.

Please call "%systemd_post syncthing@.service". We support enablement of instances through
presets, and in theory users could make use of this by providing a local preset.

> $ rpm -E "%systemd_postun_with_restart syncthing@*.service"
>  
> if [ $1 -ge 1 ] && [ -x /usr/bin/systemctl ]; then 
>     # Package upgrade, not uninstall 
>     for unit in syncthing@*.service; do 
>          /usr/bin/systemctl set-property $unit Markers=+needs-restart || : 
>     done 
> fi 
...
> And the "systemctl try-restart" command supports globs, while the "systemctl
> set-property" command does not.
> So this is really a regression in the systemd RPM scriptlets between Fedora
> 33 and 34.

Yes.

Comment 8 Fedora Update System 2021-08-06 20:23:45 UTC
FEDORA-2021-8480a19a6f has been submitted as an update to Fedora 34. https://bodhi.fedoraproject.org/updates/FEDORA-2021-8480a19a6f

Comment 9 Fedora Update System 2021-08-07 14:12:27 UTC
FEDORA-2021-8480a19a6f has been pushed to the Fedora 34 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2021-8480a19a6f`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2021-8480a19a6f

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 10 Fedora Update System 2021-08-08 01:04:09 UTC
FEDORA-2021-8480a19a6f has been pushed to the Fedora 34 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.