Skip to content
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

ostree: move admindir to /etc/alternatives.admindir #134

Closed
wants to merge 1 commit into from

Conversation

vrothberg
Copy link
Contributor

@vrothberg vrothberg commented Jul 25, 2024

ostree container commit wipes /var and thereby erases the data in
/var/lib/alternatives; the directory used to store configs/symlinks of
alternatives.

/var is not a good place for storing such configs since it won't receive
updates on bootc images either. We need to move to another location.

Hence, use /etc/alternatives.admindir when running on an ostree-based
system unless /var/lib/alternatives is already present; a user may have
worked around the problem. This way we enable alternatives to work on
ostree-based systems without breaking backwards compat.

Fixes: #9
Signed-off-by: Valentin Rothberg vrothberg@redhat.com

@vrothberg
Copy link
Contributor Author

@cgwalters @Conan-Kudo @travier @mrguitar what do you think?

@vrothberg
Copy link
Contributor Author

I think one more option could be to auto-detect running on an ostree-based system and then use the "new" path.

@vrothberg vrothberg force-pushed the ostree-alternatives branch 3 times, most recently from 70e18ae to d31c62f Compare July 25, 2024 08:59
@vrothberg
Copy link
Contributor Author

Fixed the build warnings by removing redundantly listed files in the .spec. CI didn't fire for 6 months.

@travier
Copy link

travier commented Jul 25, 2024

You'll probably want to use another folder instead of a subfolder to avoid any potential name conflict with existing configs. /etc/alternatives-config for example.

As for the migration, one option would be to migrate the config from /var to /etc and then make a symlink (/var/lib/alternatives -> /etc/alternatives-config) so that any future config is written in the right place.

@travier
Copy link

travier commented Jul 25, 2024

I think one more option could be to auto-detect running on an ostree-based system and then use the "new" path.

That's probably a good option as well. It would have to:

  • Make sure /var/lib/alternatives does not exists
  • Look for /run/ostree-booted (only available at runtime)
  • Look for /ostree (available inside a container)
  • Then use the new path

alternatives.c Outdated Show resolved Hide resolved
chkconfig.spec Show resolved Hide resolved
po/chkconfig.pot Outdated
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-01-09 12:58+0100\n"
"POT-Creation-Date: 2024-07-24 11:00+0200\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious change; I think gettext will do this by default unfortunately. Could probably break out "update gettext" into a distinct PR, otherwise this would (in the extremely unlikely event someone did a different PR) create unnecessary conflicts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update before (potentially) merging

@cgwalters
Copy link
Contributor

Look for /run/ostree-booted (only available at runtime)

Or, rely on an environment variable and/or config file to opt-in? The file path could literally look like:
mkdir -p /etc/alternatives.state && dnf -y install alternatives or so.

@travier
Copy link

travier commented Jul 25, 2024

Note that this would probably need to be advertised as a Fedora Change if we don't constraint it only to ostree based systems (but even in this case too as someone could have setup things this ways already). The deadline for submitting a change for F41 is passed but it could be considered for an exception.

@vrothberg
Copy link
Contributor Author

if we don't constraint it only to ostree based systems (but even in this case too as someone could have setup things this ways already)

I want to constrain it to ostree systems only. I am not sure how somebody would have set things up already; it didn't work before. Somebody could have used the CLI flag to change the path but this would continue to work.

@travier
Copy link

travier commented Jul 25, 2024

Small name bikeshedding note: I prefer config to state as it's the config that is wrongly stored in /var. The "state" symlinks are already in /etc.

Another option, not touching code, would be to do the migration in the %pre scriptlet + a systemd unit at boot time.

In the %pre scriplet:

  • If /var/lib/alternatives does not exists yet (always the case during rpm-ostree composes), then setup the symlink and we're done.
  • If /var/lib/alternatives already exists, then migrate the content to the new /etc folder and setup the symlink. This would migrate package mode installations.

The systemd unit at boot time would trigger on /var/lib/alternatives not being a symlink and would migrate the content and create the symlink. This would migrate image mode installations.

@travier
Copy link

travier commented Jul 25, 2024

I am not sure how somebody would have set things up already; it didn't work before.

You could have manually written your own alternatives config in /var/lib/alternatives and called update-alternatives to override the default.

@vrothberg
Copy link
Contributor Author

You could have manually written your own alternatives config in /var/lib/alternatives and called update-alternatives to override the default.

If /var/lib/alternatives exists, we need to use it.

@vrothberg vrothberg changed the title ostree: store state in /etc/alternatives/state ostree: move admindir to /etc/.alternatives.admindir Jul 25, 2024
@vrothberg
Copy link
Contributor Author

@lnykryn can you take a look?

@vrothberg
Copy link
Contributor Author

Went with calling it /etc/.alternatives.admindir to be symmetric with the CLI flag.

@vrothberg
Copy link
Contributor Author

vrothberg commented Jul 25, 2024

Dockerfile to test:

FROM quay.io/fedora/fedora-bootc:40
RUN mkdir -p /etc/alternatives.admindir
COPY alternatives /usr/sbin/alternatives
RUN dnf -y install golang
RUN ls /etc/.alternatives.admindir
RUN go help > /dev/null

@cgwalters
Copy link
Contributor

Looking at the failures, there's a ton of unrelated warnings that are mostly around missing error checking from e.g. asprintf() in the unlikely but possible even of OOM.

There's clearly some UTF-8 corruption going on (I blame Python) but the fatal error is:

collect2: fatal error: cannot find ‘ld’

Ahhh...heh! So meta! Actually I think this PR is breaking installation of the linker, see this from the buildroot log:

DEBUG util.py:463:    Installing       : binutils-gold-2.40-14.fc39.x86_64                  119/153 
DEBUG util.py:463:    Running scriptlet: binutils-gold-2.40-14.fc39.x86_64                  119/153 
DEBUG util.py:463:  admindir /etc/alternatives/state invalid
DEBUG util.py:463:    Installing       : binutils-2.40-14.fc39.x86_64                       120/153 
DEBUG util.py:463:    Running scriptlet: binutils-2.40-14.fc39.x86_64                       120/153 
DEBUG util.py:463:  admindir /etc/alternatives/state invalid

(Though now I'm a bit confused since that's the buildroot install, how are we already getting the built binary there?)

@vrothberg
Copy link
Contributor Author

The weird thing is that it worked before when using /etc/alternatives/state

@vrothberg
Copy link
Contributor Author

How can it even try to use /etc/alternatives/state with the current code ? I'll continue tomorrow morning with a fresher pair of eyes.

@travier
Copy link

travier commented Jul 25, 2024

Went with calling it /etc/.alternatives.admindir to be symmetric with the CLI flag.

I don't think it should be a hidden dir. It's a "normal" config dir, just with a weird format.

@travier
Copy link

travier commented Jul 25, 2024

You could have manually written your own alternatives config in /var/lib/alternatives and called update-alternatives to override the default.

If /var/lib/alternatives exists, we need to use it.

Not sure I understand here. My suggestion is to migrate the content from /var et /etc.

@vrothberg
Copy link
Contributor Author

vrothberg commented Jul 26, 2024

I don't think it should be a hidden dir. It's a "normal" config dir, just with a weird format.

Roger that, will update.

Not sure I understand here. My suggestion is to migrate the content from /var et /etc.

I am afraid of a breaking change. Some users/workloads may depend (for whatever reason) on the content being in /var/lib/alternatives. Since alternatives never worked on ostree-based systems, we can create a new destination there while keeping the old behavior on non-ostree systems. That should avoid any breaking change to existing users.

@vrothberg vrothberg changed the title ostree: move admindir to /etc/.alternatives.admindir ostree: move admindir to /etc/alternatives.admindir Jul 26, 2024
@vrothberg vrothberg force-pushed the ostree-alternatives branch 2 times, most recently from b60ac4d to 261c2b2 Compare July 26, 2024 08:30
@lnykryn
Copy link
Member

lnykryn commented Jul 26, 2024

I am afraid of a breaking change. Some users/workloads may depend (for whatever reason) on the content being /var/lib/alternatives. Since alternatives never worked on ostree-based systems, we can create a new destination there while keeping the old behavior non-ostree systems. That should avoid any breaking change to existing users.

Unfortunately, I heard about customers that are modifying /var/lib/alternatives with customer scripts (which is terrible, but what we can do).

Generally, this approach makes sense, but I need some extra time to think it thoroughly through.

@@ -81,9 +81,7 @@ mkdir -p $RPM_BUILD_ROOT/etc/chkconfig.d
%{_sysconfdir}/chkconfig.d
%{_sysconfdir}/init.d
%{_sysconfdir}/rc.d
%{_sysconfdir}/rc.d/init.d
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this. If you also need some changes in chkconfig packaging, please create a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builds won't pass otherwise. OK to break it out into a separate commit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should figure out what is wrong here, /etc/rc.d/init.d/ is the proper dir for initscripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already %dir /etc/rc.d so it complains about init.d being listed redundantly

chkconfig.spec Show resolved Hide resolved
alternatives.c Outdated Show resolved Hide resolved
@vrothberg
Copy link
Contributor Author

I believe something's off in the CI.

I still see admindir /etc/alternatives/state invalid which uses a directory of an earlier version of this PR. Do we need to create a new PR to fix it? I have no clue how that can happen.

@lnykryn
Copy link
Member

lnykryn commented Jul 26, 2024

I believe something's off in the CI.

I still see admindir /etc/alternatives/state invalid which uses a directory of an earlier version of this PR. Do we need to create a new PR to fix it? I have no clue how that can happen.

Yeah, I saw this in the past, the problem is that, for some reason, packit creates one repo for all the builds with the changes from PR and uses the repo also when installing the build root. And ld is in buildroot and ld uses alternatives. Try one more force push.

@lnykryn
Copy link
Member

lnykryn commented Jul 26, 2024

Also, let's remove creating ALTDIR = /var/lib/alternatives in the Makefile and instead create the admin directory directly in the alternative binary on the first use (based on the detected system). Hopefully, there won't be any SELinux problem.

`ostree container commit` wipes /var and thereby erases the data in
/var/lib/alternatives; the directory used to store configs/symlinks of
alternatives.

/var is not a good place for storing such configs since it won't receive
updates on bootc images either.  We need to move to another location.

Hence, use /etc/alternatives.admindir when running on an ostree-based
system unless /var/lib/alternatives is already present; a user may have
worked around the problem.  This way we enable alternatives to work on
ostree-based systems without breaking backwards compat.

Fixes: fedora-sysv#9
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
@vrothberg
Copy link
Contributor Author

Try one more force push.

Doesn't seem to work.

@vrothberg
Copy link
Contributor Author

Also, let's remove creating ALTDIR = /var/lib/alternatives in the Makefile and instead create the admin directory directly in the alternative binary on the first use (based on the detected system). Hopefully, there won't be any SELinux problem.

Can we break that into a separate PR? I am afraid this may turn into a bigger change if others want to have /etc/alternatives also create on-demand.

@vrothberg vrothberg closed this Jul 26, 2024
@vrothberg vrothberg deleted the ostree-alternatives branch July 26, 2024 09:36
@vrothberg
Copy link
Contributor Author

vrothberg commented Jul 26, 2024

Continuing in #135 due the build root issue. Apologies for the inconvenience.

@vrothberg
Copy link
Contributor Author

Can we break that into a separate PR? I am afraid this may turn into a bigger change if others want to have /etc/alternatives also create on-demand.

Now added to the new PR.

@cgwalters
Copy link
Contributor

Yeah, I saw this in the past, the problem is that, for some reason, packit creates one repo for all the builds with the changes from PR and uses the repo also when installing the build root.

Wow...bonkers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

config files for alternatives?
4 participants