Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

butane: add systemd user unit example #295

Merged
merged 1 commit into from
Mar 28, 2023
Merged

Conversation

tormath1
Copy link
Contributor

@tormath1 tormath1 commented Mar 24, 2023

it's not that easy to create a systemd user unit from butane, I think it's nice to document it.

@tormath1 tormath1 requested a review from a team March 24, 2023 14:36
@tormath1 tormath1 self-assigned this Mar 24, 2023
Copy link
Contributor

@krnowak krnowak left a comment

Choose a reason for hiding this comment

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

Looks alright, but I don't understand why user units need the symlinks to be created by ignition, while system units don't.

Comment on lines +193 to +196
links:
- path: /etc/systemd/user/default.target.wants/hello.service
target: /etc/systemd/user/hello.service
hard: false
Copy link
Contributor

Choose a reason for hiding this comment

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

So user units require explicit creation of the symlink? As in: it's not enough to specify WantedBy in the unit file, like it's done for system units?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I removed the symlink and the unit is not enabled. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Meh, I think that this "gotcha" for user units should be spelled out in the example description. But I don't know if this is because it's a user unit, or it's because it's placed in /etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignition creates a preset file for systemd to enable the units. For user units, this should be under /etc/systemd/user-preset/ but Ignition doesn't know about that, only /etc/systemd/system-preset/.

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway there is no way to set enabled: true for the user unit because it's created as a file here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Small hint, I think you could also add one of these Upholds= drop-ins for default.target.wants but the symlink is better^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have two issues with this configuration actually:

  1. We can see the logs / the status with systemctl --user status hello.service but we can't get logs with journalctl --user --unit hello.service because core as a UID < 1000 (see: journalctl --user --unit and --user-unit differ systemd/systemd#26742)
  2. Even if we define the unit path to be /etc/systemd/user it lands into /etc/xdg/systemd/user which is not a direct issue as systemd looks into this path but can be disturbing to see systemctl --user cat hello.service showing this path...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can go ahead with this PR. We won't fix today this journalctl --user -u hello.service issue and it's tracked. The goal of this PR is to show how to create a systemd user unit, one can still get the logs with systemctl --user status hello.service

Signed-off-by: Mathieu Tortuyaux <[email protected]>
Co-authored-by: Kai Lüke <[email protected]>
@tormath1 tormath1 force-pushed the tormath1/systemduser branch from e20c419 to 469693c Compare March 28, 2023 10:09
@tormath1 tormath1 merged commit 2e4cd29 into main Mar 28, 2023
@tormath1 tormath1 deleted the tormath1/systemduser branch March 28, 2023 10:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants