#985787 init-system-helpers: deb-systemd-helper - incoherent enable after WantedBy change

#985787#5
Date:
2021-03-23 14:32:53 UTC
From:
To:
Hi,

I use debhelper to install and enable systemd user units. I noticed that
after changing the `WantedBy` value from default.target to
graphical.target the new symlink was not created.

I attach a GraphViz .dot graph which visualizes a troubling number of
states caused by `dpkg -i`. Even more troubling are the facts that:
- reinstallation of the same version changes the state,
- purging the package (`dpkg -P`) can leave dead symlinks.

What do you think about that?

About the graph:
- version 4.0 has `WantedBy=default.target`,
- version 4.3 has `WantedBy=graphical.target`,
- `link` is the state of symlinks in /etc/systemd/user/*.target.wants,
- `dsh` is the state of the .dsh-also file.

At the same time systemctl:
- `enable` would add the second link leaving the first one,
- `disable` would remove both symlinks even if one of them is no longer
  referenced by the unit file,
- `reenable` would leave only the symlink pointing to the currently
  selected target.

I have some additional questions:

Why is `no_link_installed(…)` taken into account when setting
$create_links in `enable(…)`[1]?

[1]: https://salsa.debian.org/debian/init-system-helpers/-/blob/master/script/deb-systemd-helper

Is there a reason not to just use `reenable` in postinst scripts?

An old discussion in #717603 suggests[2] that it was intended to take
changes in the [Install] section into account.

[2]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=717603

#985787#10
Date:
2021-03-23 15:20:18 UTC
From:
To:
Am 23.03.21 um 15:32 schrieb Marcin Szewczyk:

If you change the WantedBy target, you need to do that manually on
upgrades, i.e. manually remove the old enablement symlink and purge the
existing i-s-h state.

This happens rarely enough, that adding explicit support for that in
i-s-h is probably not worth the complications.
That said, if someone can come up with a clean patch to do that, I'm
happy to take a look.

Regards,
Michael

#985787#25
Date:
2021-03-24 12:52:01 UTC
From:
To:
I attach a patch (against debian/1.60). It differs from the one in
#797108. Maybe it goes in an acceptable direction. Please take a look if
you have some time.

Pardon my Perl. I have not used it for 15 years.

From the commit message:

#985787#30
Date:
2021-03-24 15:05:27 UTC
From:
To:
Am 24.03.21 um 13:52 schrieb Marcin Szewczyk:

Thanks, very much appreciated!