Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I just finished the install and setup process of systemd on my arch-linux system (2012.09.07). I uninstalled initscripts (and removed the configuration files).

What I want to do is create a service that can be started and stopped by a non-root user. The service is to start a detached screen session running rtorrent. However I want every user on the system who has set this service to start (enabled) to have a particular instance started for them specifically. How would one go about doing this?

I remember reading that systemd supports user instances of services, however I have been unable to find any information on how to set this up, or whether it relates to what I am looking for.

Service file that I have used for system:

[Unit]
Description=rTorrent

[Service]
Type=forking
ExecStart=/usr/bin/screen -d -m -S rtorrent /usr/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 /usr/bin/rtorrent

UPDATE#1:

After reading through the man pages here and here, I understand how systemd works a bit better. Specifically that using the User= and WorkingDirectory= options allow for the service to be started in a user's session. However the issue still remains that the user themselves can not start, stop, enable, or disable the service. An Access is denied error is given by systemctl.

UPDATE#2:

First off, for simplification and for better use of systemd's user session (still somewhat incomplete) feature, I used sofar's user-session-units and followed his config advice.

It seems that there is a bug in the current version of DBus (1.6.4-1) in which it does not set the environment variable DBUS_SESSION_BUS_ADDRESS meaning using the systemctl --user command errors out with:

Failed to get D-Bus connection: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

The variable should look like this:

DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/USERUID/dbus/user_bus_socket"

where USERUID needs to be the UID of the given user.

share|improve this question
    
I realize that one could create a separate service file per user, and simply enable it. However I just want to know if it could be possible the way I have described it above. –  Hans Sep 17 '12 at 23:34
    
Fair enough, I could simple setup sudo for the users and have them, as mentioned in my comment above, control their own service file. However this solution would allow the user to control most other services as well... –  Hans Sep 19 '12 at 11:10
    
It wouldn't, if you had read sudo's documentation – sudoers(5) has many examples on restricting a command's arguments. –  grawity Sep 20 '12 at 12:23
add comment

1 Answer

up vote 6 down vote accepted

systemd does not allow ordinary users to start system services (except by using SELinux, which Arch does not support).

Since rtorrent is not actually a system service, and because you want every user to have their own instance of rtorrent, experiment with systemd's "user" mode.

If you start the user@Hans.service system unit, it will launch a separate instance of systemd for the user "Hans". The new user-systemd will read unit files (starting with default.target) from ~/.config/systemd/user/, /etc/systemd/user/ and /usr/lib/systemd/user/.

share|improve this answer
1  
Thanks grawity, that was basically what I was missing. However it also turns out to have been a DBus problem as well: there seems to be a bug in dbuse that doesn't set the correct global variable DBUS_SESSION_BUS_ADDRESS for a given user, so systemctl can't access the user session, it errors our. Once I figured out this small problem, everything else works beautifully! –  Hans Sep 25 '12 at 10:05
1  
@Hans: Yes, there's a patch for that. –  grawity Sep 25 '12 at 12:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.