Please help in starting a user service with systemctl

Dear friends,
I am trying to start rtorrent in the cleanest way as user osmc.

This is /etc/systemd/user/rt.service:

[Unit]
Description=rTorrent
After=network.target

[Service]
Type=forking
KillMode=none
ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 /usr/bin/rtorrent
WorkingDirectory=%h

[Install]
WantedBy=multi-user.target

but when I try to enable it I get the following error:

osmc@osmc:/etc/systemd/user$ sudo systemctl --user enable rt
Failed to get D-Bus connection: Connessione rifiutata

Any ideas on how to fix this or have a simpler/better alternative means of restarting rtorrent after every reboot by the user osmc ? FWIW if I define rt.service as a SYSTEM service it starts allright but owned by root (which I want to avoid).

For the time being as a stopgap measure I have a start|stop type script which I manually launch from osmc home but of course this will not be launched if the system goes down and then reboots.

Thank you

There’s no need to try to make it it a “user service”. Just specific User=osmc, Group=osmc in the service. Here’s an example from our transmission service:

1 Like

Thank you very much. FWIW here is the /etc/systemd/systm/rt.service file to have rtorrent started at boot time on behalf of regular user osmc (tested working):smile:

[Unit]
Description=rtorrent
After=network.target

[Service]
User=osmc
Group=osmc
Type=forking
KillMode=none
ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 /usr/bin/rtorrent
WorkingDirectory=%h

[Install]
WantedBy=multi-user.target

You likely wanted to run only systemctl --user enable rt (without sudo which does not make any sense here). What you probably wanted to do was:

  1. place the file into /home/osmc/.config/systemd/user/rt.service
  2. make sure WantedBy is set to default.target (multi-user.target does not do the job)
  3. enable the service and reboot
systemctl --user enable rt
sudo reboot

Note that all commands above are to be run under osmc.

This post is over seven years old – is there a specific reason you reopened it?

Cheers

Sam

Even 7 years later the question is relevant (although it’s a bit more related to systemd in general than to OSMC itself). Although I did not find a way to run user services in OSMC documented anywhere else.