Skip to content

Conversation

cgwalters
Copy link
Member

In ostreedev/ostree#3513 i'm trying to ensure that all the ostree mounts are cleaned up. It turned out that it was this unit keeping /var open because the journalctl binary doesn't know to stop tracking the /var/log/journal files when the daemon has flushed.

(We could obviously fix systemd to handle this)

But anyways the main reason this exists is to forward logs from startup and especially entering emergency.target. While it's useful to get logs from shutdown, there are other ways to do that.

This makes var.mount reliably unmounted for me.

In ostreedev/ostree#3513 i'm trying to
ensure that all the ostree mounts are cleaned up. It turned
out that it was *this* unit keeping `/var` open because
the `journalctl` binary doesn't know to stop tracking the
`/var/log/journal` files when the daemon has flushed.

(We could obviously fix systemd to handle this)

But anyways the main reason this exists is to forward logs
from startup and especially entering emergency.target. While
it's useful to get logs from shutdown, there are other ways
to do that.

This makes `var.mount` reliably unmounted for me.
# won't be added to this unit, which would cause it to get
# taken down when isolating to emergency.target
DefaultDependencies=no
After=systemd.journal.service
Copy link
Member Author

Choose a reason for hiding this comment

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

Also this was always wrong and did nothing, we now use the socket correctly

Copy link
Member

Choose a reason for hiding this comment

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

i.e. systemd.journal.service should have been systemd-journal.service ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably yes, but it's more correct to be after the socket, which is what we want to talk to

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to ensure the virtio journal streaming service is terminated correctly on shutdown to prevent it from holding /var open. The changes to the systemd unit file are mostly correct, but I've identified a potential race condition with the use of Conflicts=shutdown.target and have provided a suggestion to improve the shutdown ordering robustness.

Comment on lines +1656 to +1657
# Do get killed on shutdown
Conflicts=shutdown.target
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While Conflicts=shutdown.target makes the intent clear, it might introduce a race condition during shutdown. According to systemd.unit(5), Conflicts= dependencies are orthogonal to After= and Before= ordering dependencies.

Since both this unit and local-fs.target have Conflicts=shutdown.target, when shutdown.target is activated, systemd will stop both units, but their relative order is not guaranteed by the After=local-fs.target directive. This could lead to this service being stopped after local-fs.target, which would re-introduce the problem this PR aims to solve.

The After=local-fs.target directive is sufficient to ensure this unit is stopped before local-fs.target during a graceful shutdown. Removing the Conflicts=shutdown.target will rely on this ordering, which is more deterministic.

Copy link
Member

Choose a reason for hiding this comment

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

Do we need Conflicts=shutdown.target because we have IgnoreOnIsolate=true ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, and I think Gemini's review doesn't understand the semantics here with IgnoreOnIsolate.

That said IgnoreOnIsolate can create very messy situations like this and it'd definitely be better to try to kill this unit entirely...

Copy link
Member

Choose a reason for hiding this comment

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

right. and we have IgnoreOnIsolate because we want to continue to log even when heading into emergency.target.

Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

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

LGTM

@dustymabe dustymabe merged commit 0b60629 into coreos:main Aug 28, 2025
4 of 6 checks passed
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.

2 participants