Ask Your Question
0

How do I control a systemd user service?

asked 2018-01-05 01:35:17 -0500

l0b0 gravatar image

updated 2018-01-05 01:36:24 -0500

Some services, like pulseaudio, are run as user services by default. I can't find any way to control such services using the service resource. The windows service provider description mentions that "running services as a specific user" is not possible, indicating that it should be possible with other providers (otherwise the comment would apply to all providers rather than just the windows one). Is this possible for systemd?

Using Puppet 5.3.3 on Arch Linux.

edit retag flag offensive close merge delete

Comments

Puppet is a _system_ configuration tool. Don't interfere with the user's (running) environment. Especially not as root, unless requested. For pulseaudio this means, you adequately prepare it, and the users by _theirown_ start/use pulseaudio given your distributed settings.

Kai Burghardt gravatar imageKai Burghardt ( 2018-01-06 23:33:47 -0500 )edit

Not a direct solution, but you could have the user's .bash_profile check if the service is started, and start it if it isn't, when they log in, but it is not a direct 'solution' to your problem of running the service as a specific user... hrm....

DarylW gravatar imageDarylW ( 2018-01-09 13:29:56 -0500 )edit

I know that we have done similar things to this, to ensure that a VNC server was running as a specific user on systemd, I'll have to see how we did it.

DarylW gravatar imageDarylW ( 2018-01-09 13:30:43 -0500 )edit

In my comment below, we configure systemd to have the 'User' directive under the 'Service' section of the unit file.. the 'systemd' service is still run as root, but the systemd system de-escalates the process down to the user specified in the directive

DarylW gravatar imageDarylW ( 2018-01-09 13:57:37 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-01-09 13:56:08 -0500

DarylW gravatar image

It looks like in our .service file, we have

[Service]
User=<%= @user %>

That should work following the idea listed in this askubuntu answer- https://askubuntu.com/a/676022

You can specify the directives User= and Group= in the [Service] section of the unit file.

Also, you may work on solving your problem in different ways.... with a little googling... See if this works for you to run the System Wide Daemon, even though it is not the recommended way of running it..

https://www.freedesktop.org/wiki/Soft... https://rudd-o.com/linux-and-free-sof...

edit flag offensive delete link more

Comments

1

Huh, of course, specifying `User=` in the service unit file. For some reason I assumed, l0b0 primary issue is to talk to the service manager of the calling user (compare `--user` in `systemctl(1)`) [so the user remains capable of managing units (like pulseaudio) which are run as him].

Kai Burghardt gravatar imageKai Burghardt ( 2018-01-09 20:21:29 -0500 )edit

pulseaudio.service does not have a `User` directive, but I guess this could work.

l0b0 gravatar imagel0b0 ( 2018-01-11 02:33:02 -0500 )edit
1

the User directive is a part of systemd... even if it isn't in your Unit file, you can add it.

DarylW gravatar imageDarylW ( 2018-01-15 09:24:49 -0500 )edit
0

answered 2018-01-11 12:56:30 -0500

gabe_sky gravatar image

Also, remember that the Service type will take attributes for "start," "stop," "status," and "restart." So you could just supply nohup/sudo commands that get systemd to start the service as some user.

https://puppet.com/docs/puppet/5.3/type.html#service
edit flag offensive delete link more

Comments

I don't think you can set the 'user' parameter on the service call when doing a 'base' service, right? You would have to do some su magic with usernames being interpolated into the command strings, which is a bit ugly but doable

DarylW gravatar imageDarylW ( 2018-01-15 09:25:53 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-01-05 01:35:17 -0500

Seen: 213 times

Last updated: Jan 11