Skip to content

Conversation

@traylenator
Copy link
Contributor

@traylenator traylenator commented Oct 23, 2025

Pull Request (PR) description

Create a new function systemd::systemctl_user to construct array of command and args used to contact systemd --user instances so systemctl --user status my.service can be executed.

On systemd >= 256 run0 is used with runuser used on older OSes (RHEL9, Debian 12, .. )

A new boolean is also added install_runuser to install util-linux if needed which seems to be the correct package for all distributions. In reality this package will be installed on most systems anyway.

We switch to using runuser or run0 to become the user since:

  • Using systemctl or systemd-run with --machinectl [email protected] always fails when puppet is ran inside its own systemd unit. I believe systemd services can not access systemd --user instances.
  • We use runuser -u $user rather than a user => $user on the exec since the $(id -u $user) must be resolved late within the exec itself.

Now the command is generated inside a function this will make future improvements to this method much simpler.

This Pull Request (PR) fixes the following issues

@traylenator traylenator added the enhancement New feature or request label Oct 23, 2025
@traylenator traylenator force-pushed the runuser branch 4 times, most recently from bd09440 to 5d75c89 Compare October 23, 2025 16:09
@kenyon kenyon changed the title Use runuser to connect to systemd --user instance Use runuser to connect to systemd --user instance Oct 23, 2025
Create a new function `systemd::systemctl_user` to construct
array of command used to contact `systemd --user` instance so
`systemctl --user status my.service` can be executed.

In addition we switch to using `runuser` or `run0` for systemd >= 256 to become the user.

* Using `systemctl` or `systemd-run` with --machinectl [email protected]
  always fails when puppet is ran inside its own systemd unit.
  I believe systemd services can not access `systemd --user` instances.
* We use `runuser -u $user` rather than a `user => $user` on the exec
  since the $(id -u $user) must be resolved late within the exec itself.

Now the command is generated inside a function this will make future
improvements to this method much simpler.
@traylenator traylenator changed the title Use runuser to connect to systemd --user instance Use runuser/run0 to connect to systemd --user instance Oct 24, 2025
@traylenator
Copy link
Contributor Author

Very happy to remove the systemd::runuser parameter and rely on documentation?

@traylenator traylenator marked this pull request as ready for review October 24, 2025 09:52
@traylenator traylenator merged commit 7d8598c into voxpupuli:master Oct 24, 2025
21 checks passed
@traylenator traylenator deleted the runuser branch October 24, 2025 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

systemd::user_service broken for puppet running in background

3 participants