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

Better support for portable user service files (rootless). #19690

Closed
gnat opened this issue May 21, 2021 · 6 comments
Closed

Better support for portable user service files (rootless). #19690

gnat opened this issue May 21, 2021 · 6 comments
Labels
needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer pid1

Comments

@gnat
Copy link

gnat commented May 21, 2021

Is your feature request related to a problem? Please describe.

I'm writing *.service files in ~/.config/systemd/user/ for user level systemd (systemctl --user) service management.

The problem is ExecStart must be an absolute path and cannot use %h. This forces me to have service files that are not portable between users. ExecStart= is pointing to binaries in /home/USER/.local/bin

This path is important as users run more rootless daemons, rootless containers (ex: rootless docker) for security and isolation.

Describe the solution you'd like

  • Perhaps add %h/.local/bin to the $PATH when running as --user ?
  • Perhaps allow %h in ExecStart=. Example: ExecStart=%h/.local/bin/cockroach ?
  • Perhaps an option to automatically add %h to ExecStart= when running as systemctl --user ?

The systemd version you checked that didn't have the feature you are asking for

Any assistance, suggestions welcome. Thank you!

@mbiebl
Copy link
Contributor

mbiebl commented May 21, 2021

The problem is ExecStart must be an absolute path

This is not true anymore. ExecStart nowadays consults $PATH if a non-absolute path is specified.

@gnat
Copy link
Author

gnat commented May 21, 2021

This is not true anymore. ExecStart nowadays consults $PATH if a non-absolute path is specified.

Please elaborate or correct me if I'm wrong but I get the following error
May 21 21:25:27 ubuntu systemd[1012]: /home/gnat/.config/systemd/user/cockroach@.service:30: Executable "cockroach" not found in path "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

This is after setting Environment=PATH=/home/gnat/bin:/home/gnat/.local/bin:/sbin:/usr/sbin:$PATH in my cockroach@.service file.

The documentation reads:

If the command is not a full (absolute) path, it will be resolved to a full path using a fixed search path determined at compilation time. Searched directories include /usr/local/bin/, /usr/bin/, /bin/ on systems using split /usr/bin/ and /bin/ directories, and their sbin/ counterparts on systems using split bin/ and sbin/.

"determined at compilation time" unfortunately doesn't help in this situation.

@gnat
Copy link
Author

gnat commented May 22, 2021

Added another solution suggestion of adding %h/.local/bin to the $PATH when running as systemctl --user.

@mbiebl
Copy link
Contributor

mbiebl commented May 22, 2021

You're right, the paths are hard-coded during compilation time. For the user instance, there is the -Duser-path meson option:
https://github.com/systemd/systemd/blob/main/meson_options.txt#L77
https://github.com/systemd/systemd/blob/main/meson.build#L866

I do think that adding ~/.local/bin by default to the user-path would be a good idea.

@poettering
Copy link
Member

The problem is ExecStart must be an absolute path and cannot use %h.

It cannot use %h? What makes you think so?

@poettering poettering added needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer pid1 labels May 25, 2021
@gnat
Copy link
Author

gnat commented Jun 19, 2021

Ended up writing some fresh service files today and to my happy surprise %h and %u are working awesomely in ExecStart=. This must have been a mistake on my end.

Thank you for your patience. Will go ahead and close this.

For the future I do think it would be helpful to add ~/.local/bin to the default PATH when invoking systemctl --user.

@gnat gnat closed this as completed Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer pid1
Development

No branches or pull requests

3 participants