-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There are some cases where the unit file enablement state might be surprising #9569
Comments
I'm wondering why the code doesn't simply search for symlinks in paths ending with .wants.d/.requires.d to figure out if a unit is enabled or not... |
so we'd need some solid reasoning if we were going to start some transition there.
Here is a counter-example:
|
That is, if you want to enable by installing a symlink in |
I don't really see why and we agreed that distro defaults (defined by presets) should live in /usr/lib... |
systemd "presets", live in /usr/lib/systemd/system-preset/. But when you run There is a very solid reason for this. If you declare your unit with We never want |
Well, a unit should be one of two things: "statically" enabled, in which case it should have one or more symlinks that enabled it in /usr, and not carry an [Install] section, or be "dynamically" enabled, in which case it should carry an [Install] section, and no symlinks in /usr. In your case you are creating something that both declares that it is something the user should enable, but then you enable it statically anyway. So yes, this will confuse systemd, because you did contradicting stuff with it. Decide whether the user shall enable it or if it is enabled statically. In the former case make it carry an [Install] section, and in the latter, remove any such section. |
Well, aliases are considerd "enabling", this goes through the entire design, i.e. that's why there is an "Alias=" stanza in [Install] after all. We generally are quite permissive when checking how a unit is enabled: we do not verify whether the configuration in effect matches the one in [Install] in order to allow user modification, and allow sane upgrades: unit files may change their [Install] sections if they like, which is considered if the unit is enabled some time later, but this shouldn't change the fact that the unit was previously enabled. Also, this logic also matches the logic in "systemctl disable" which removes all symlinks in /etc, regardless of their name. Quite frankly, yes, there's some niche behaviour that might be surprising, but I think it is quite systematic the way it is. |
So, I am not sure what we should do with this issue. i.e. please be more precise in what you are requesting. |
@poettering that's not what we agreed on in issue #4830: in my understanding we decided to separate the choices of the admins from the distro's ones. If sysadmin chooses to disable a service for example, this should be made persistent no matter how the preferences of the distro (presets) will evolve. And this looks cleaner IMHO. Regarding the current implementation, dependency symlinks are always in .require/.wants directories so the implementation should look into this directory only in order to figure out if a service is enabled/disabled. This seems more robust than the current code which simply searches for the symlinks in /etc/systemd/system as it can be easily fooled by some cases. |
Sure, but so far nobody implemented #4830. We can certainly implement that, but until then, with the change of semantics that will introduce the current logic applies, and in that logic doing [Install] and doing symlinks in /usr is somewhat contradictory |
again, there's |
Actually I was looking at it and found out that the current logic is pretty fragile even though it works with the usual cases by now.
OK then if we extend the logic to handle dependency symlinks in /usr/lib, wouldn't it be appropriate to rewrite the logic so
Thanks. |
i
As I wrote twice above, we should really consider alias symlinks as ways to enable a unit, too, as Alias= is a commonly used part of [Install] and often the only one, and hence should have an effect on the enablement state |
OK got your point now. I thought that the enablement state was only something related to the unit being able to be pulled in (and therefore activated) somehow but it seems that it's more related to "systemctl enable" being called. But if we still follow this logic and once distros will be able to install symlinks in /usr/lib (according to the preset states), a unit could be reported as disabled whereas it will be pulled in via a symlink installed in /usr/lib/. Is that what you have in mind ? That might be confusing but maybe it's just me... |
Well, when we add that i figure we need to revisit this logic, and probably consider all symlinks in all dirs (i.e. both /etc and /usr), and then remove all symlinks that are masked from that list, and then report if the result set is empty as "disabled" and otherwise as "enabled", or so. but dunno, there might be some corner cases I am not seeing... |
Ah. I did not know there was a specific agreement being referred to. So far I agree with poettering. I think currently IIUC, we're currently in a confusing transition period where we've got an added feature in #5231, but we don't yet have the support particularly in What I might be missing is that I haven't quite gotten my head round the original motivation. I'm imagining it works nicely in a distribution which does not use |
I've always found this case pretty moot actually: "systemctl is-enabled ctrl-alt-del.target" reports that the target is disabled but if I press Ctrl+Alt+Del then the system will still reboot since the alias actually exists (in /usr).
In my understanding packages will drop symlinks into /usr still based on the preset states so services are still enabled/disabled based on the distro policies by default. This is mainly to avoid cluttering /etc with symlinks which are distro defaults. |
OK though we could revisit the logic right now as it wouldn't hurt I think. In fact it might even improve the previous example given by @sourcejedi with |
I must admit that the code is pretty hard to follow so I may miss something but some testing (see below) seems to confirm that there are some shortcomings at least ;)
For example it tries to search for any symlink pointing to a given unit in the loading paths and if (and only if) such a symlink is found in /etc/systemd/system then the unit is considered as enabled.
Such logic can lead to false-positives:
It would be nice if the code could be improved in this area.
The text was updated successfully, but these errors were encountered: