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

RPM triggers: rewrite in shell #8550

Closed
wants to merge 1 commit into from

Conversation

cgwalters
Copy link
Member

This is compatible with rpm-ostree, which implements offline and
transactional updates by creating a new root, sandboxing each RPM script
in a bwrap container: coreos/rpm-ostree#749

Further, the "test for a directory and run a binary" pattern is significantly
shorter and more obvious in shell script.

Discussion in: #8090 (comment)

One counter was that this causes systemd to depend on /bin/sh, but that's
true today in Fedora at least, and I'd be extremely surprised if there were a
distribution where that wasn't the case. Down the line RPM could probably
learn to omit Requires for %transfiletrigger on /bin/sh.

Downstream: https://bugzilla.redhat.com/show_bug.cgi?id=1559141

Copy link
Contributor

@Conan-Kudo Conan-Kudo left a comment

Choose a reason for hiding this comment

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

NAK.

You should really just implement a Lua subprocess thing in rpm-ostree.

# upgraded. We care about the case where a package is initially
# installed, because other cases are covered by the *un scriptlets,
# so sometimes we will reload needlessly.
if test -d /run/systemd/system; then %{_bindir}/systemctl daemon-reload; fi
Copy link
Member

Choose a reason for hiding this comment

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

is there any benefit in doing this one line? why not break this the way people would expect, i.e. in three lines?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine doing that if you prefer. I thought the one-liner emphasized just how much simpler shell is over Lua, but again I can easily change it.

Copy link
Member

Choose a reason for hiding this comment

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

we tend to prefer readability over density

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, updated to be multi-line ⬇️

# This script will process files installed in @sysusersdir@ to create
# specified users automatically. The priority is set such that it
# will run before the tmpfiles file trigger.
if test -d /run/systemd/system; then %{_bindir}/systemd-sysusers; fi
Copy link
Member

Choose a reason for hiding this comment

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

as above, why compress this into one line?

Copy link
Member

Choose a reason for hiding this comment

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

i mean, if you want to compress this into one line, why not do:

test -d … && …?

Copy link
Member Author

Choose a reason for hiding this comment

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

test -d … && …?

I actually did it that way to start, but then remember in shell that will result in exit 1 and hence RPM complaining about script failures... (and on a related note, in rpm-ostree by default script failures are fatal)

Copy link
Member

Choose a reason for hiding this comment

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

ok

@poettering
Copy link
Member

NAK.

You should really just implement a Lua subprocess thing in rpm-ostree.

Does rpm even have hooks for that?

@poettering poettering added the rpm label Mar 22, 2018
@Conan-Kudo
Copy link
Contributor

Does rpm even have hooks for that?

@poettering As rpm-ostree doesn't actually use librpm for most of its work, it's really up to @cgwalters to actually implement the functionality he's replacing.

I'm not inclined to entertain this because the rewrite to Lua was deliberate to make the scriptlet execution safer and more predictable.

@cgwalters
Copy link
Member Author

scriptlet execution safer

If we're talking about safety I think rpm-ostree provides more value to the FOSS ecosystem than having scripts written in Lua. We've written and maintain a system that allows you to always safely pull the power while preparing a system update. And you can still install packages. We go to a lot of effort to have rpm-ostree install postgresql-server not touch your running system! Specifically again on this topic, we don't want that to invoke systemctl daemon-reload.

Anyways, at some point we probably will do the "lua as external subprocess", but bear in mind that things were working fine for Fedora Atomic {Host,Workstation} before this code landed in systemd.

# installed, because other cases are covered by the *un scriptlets,
# so sometimes we will reload needlessly.
if test -d /run/systemd/system; then
%{_bindir}/systemctl daemon-reload
Copy link
Member

Choose a reason for hiding this comment

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

the other shell code uses 4ch indenting, no? please stick to the same across the whole file

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, fixed ⬇️

# specified users automatically. The priority is set such that it
# will run before the tmpfiles file trigger.
if test -d /run/systemd/system; then
%{_bindir}/systemd-sysusers
Copy link
Member

Choose a reason for hiding this comment

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

as above

@Conan-Kudo
Copy link
Contributor

Conan-Kudo commented Mar 22, 2018

If we're talking about safety I think rpm-ostree provides more value to the FOSS ecosystem than having scripts written in Lua.

I might consider that, if it weren't for the fact it can't handle large classes of RPMs as it is. Nothing with %verifyscript (bye SUSE systems!), nothing with Lua scriptlets (bye embedded systems and low-level packages in many Linux distributions), and nothing with %pretrans (though this might be a bit of a meh, since it just ignores %pretrans...).

This is compatible with rpm-ostree, which implements offline and
transactional updates by creating a new root, sandboxing each RPM script
in a bwrap container: coreos/rpm-ostree#749

Further, the "test for a directory and run a binary" pattern is significantly
shorter and more obvious in shell script.

Discussion in: systemd#8090 (comment)

One counter was that this causes systemd to depend on `/bin/sh`, but that's
true today in Fedora at least, and I'd be extremely surprised if there were a
distribution where that wasn't the case.  Down the line RPM could probably
learn to omit `Requires` for `%transfiletrigger` on `/bin/sh`.

Downstream: https://bugzilla.redhat.com/show_bug.cgi?id=1559141
@Conan-Kudo
Copy link
Contributor

Conan-Kudo commented Mar 24, 2018

Down the line RPM could probably learn to omit Requires for %transfiletrigger on /bin/sh.

I didn't notice this immediately, but as I read this now, I realize that what you're asking for is nuts. You realize that I can technically set any scriptlet to any interpreter I want, right? I can even set it to Perl, Python, or any other heavyweight interpreters. I could even set it to PowerShell! It would be asinine to even consider not exporting the interpreter requires for scriptlets...

@cgwalters
Copy link
Member Author

I didn't notice this immediately, ...

Do note the last two words in the (offhand) proposal: "on `/bin/sh".

@keszybz
Copy link
Member

keszybz commented Mar 26, 2018

Hmm, so, I understand that the late landing of this feature in Fedora causes an issue for rpm-ostree. It would be reasonable to use your patch in Fedora for some time. (But note that the version in Fedora is already slightly different than the one upstream, since the upstream version does not support the split of systemd-udev subpackage).

I'm not convinced that we want to replace lua with shell. I think that since it's legal (and encouraged) to use lua in Fedora, there will be more and more scriptlets using lua. Right now there aren't that many, but there are some. And right now we have a bazillion useless scriptlets, so a single one is barely noticeable. But the efforts to prune the useless ones significantly have already begun, and then the remaining scriptlets will be more visible, and the benefit from rewriting them in lua to reduce the dependencies a bit will be stronger.

In the longer run, I expect that rpm-ostree will need to learn to run lua scriptlets too. And actually this shouldn't be too onerous: I know that the lua environment in rpm is a bit special, but afaik it differers primarily in the list of modules that are available, so it should be possible to recreate the same environment.

What about doing this just in Fedora for the time beeing?

@cgwalters
Copy link
Member Author

What about doing this just in Fedora for the time beeing?

That's OK with me.

@cgwalters
Copy link
Member Author

@dustymabe
Copy link

https://src.fedoraproject.org/rpms/systemd/c/8e6b39457b3e2660793821e0524855226e33e306?branch=master

This was done with some urgency to un-break f28 beta for Atomic Host.

@keszybz
Copy link
Member

keszybz commented Mar 28, 2018

Well, OK. Let's continue the discussion in the Fedora bugtracker.

@keszybz keszybz closed this Mar 28, 2018
yuwata pushed a commit to yuwata/systemd-fedora that referenced this pull request Apr 16, 2018
  This fixes compatibility with rpm-ostree.
yuwata pushed a commit to yuwata/systemd-fedora that referenced this pull request Apr 16, 2018
  This fixes compatibility with rpm-ostree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

5 participants