Sample Header Ad - 728x90

How to run rtorrent as systemd service under a dedicated user?

4 votes
4 answers
6461 views
I am trying to get rtorrent to run as a systemd service, but the service wouldn't start. Here's the config file and any log I can get. Ask for more info if you need to. I am running:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal
$ systemctl status rtorrent
● rtorrent.service - rTorrent
     Loaded: loaded (/etc/systemd/system/rtorrent.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2021-05-27 08:52:43 EEST; 5min ago
    Process: 20199 ExecStart=/usr/bin/tmux new-session -d -P -s rt -n rtorrent /usr/bin/rtorrent (code=exited, status=0/SUCCESS)
    Process: 20205 ExecStop=/usr/bin/tmux send-keys -t rt:rtorrent C-q (code=exited, status=1/FAILURE)
   Main PID: 20201 (code=exited, status=0/SUCCESS)

May 27 08:52:43 $MACHINE systemd[1] : Starting rTorrent...
May 27 08:52:43 $MACHINE tmux: rt:
May 27 08:52:43 $MACHINE systemd[1] : Started rTorrent.
May 27 08:52:43 $MACHINE tmux: no server running on /tmp/tmux-110/default
May 27 08:52:43 $MACHINE systemd[1] : rtorrent.service: Control process exited, code=exited, status=1/FAILURE
May 27 08:52:43 $MACHINE systemd[1] : rtorrent.service: Failed with result 'exit-code'.
The config file..
/etc/systemd/system/rtorrent.service 
[Unit]
Description=rTorrent
Requires=network.target local-fs.target

[Service]
Type=forking
KillMode=none
User=rt
Group=adm
ExecStart=/usr/bin/tmux new-session -d -P -s rt -n rtorrent /usr/bin/rtorrent
ExecStop=/usr/bin/tmux send-keys -t rt:rtorrent C-q
WorkingDirectory=/tmp/tmux-110/

[Install]
WantedBy=multi-user.target
Some more logs:
$ journalctl -u rtorrent
May 27 08:52:43 $MACHINE systemd[1] : Starting rTorrent...
May 27 08:52:43 $MACHINE tmux: rt:
May 27 08:52:43 $MACHINE systemd[1] : Started rTorrent.
May 27 08:52:43 $MACHINE tmux: no server running on /tmp/tmux-110/default
May 27 08:52:43 $MACHINE systemd[1] : rtorrent.service: Control process exited, code=exited, status=1/FAILURE
May 27 08:52:43 $MACHINE systemd[1] : rtorrent.service: Failed with result 'exit-code'.
So far I have added the user rt to the adm group, but I can't figure it out why tmux can't be started as rt. I also authorized rt user to launch services thanks to the enable-linger option: loginctl enable-linger rt I first added the rt user with:sudo adduser --system --gecos "rTorrent Client" --disabled-password --group --home /home/rt rt. How to make rtorrent run as systemd service with tmuxas a dedicated user? Or is there any other way to run it as service with systemd? Any help is really appreciated. **UPDATE:** So, just to get a fresh start, I have created a new user named rtorrent with: sudo adduser --system --gecos "rTorrent System Client" --disabled-password --group --home /home/rtorrent rtorrent and changed the /etc/systemd/system/rtorrent.service file to this (also adding system.daemon = true in /home/rtorrent/.rtorrent.rc, because of this post ):
[Unit]
Description=rTorrent System Daemon
After=network.target

[Service]
Type=simple
User=rtorrent
Group=rtorrent

ExecStartPre=-/bin/rm -f /home/rtorrent/.session/rtorrent.lock
ExecStart=/usr/bin/rtorrent -o import=/home/rtorrent/.rtorrent.rc
Restart=on-failure
RestartSec=3

[Install]
WantedBy=multi-user.target
But after all I get this error:
$ systemctl status rtorrent
● rtorrent.service - rTorrent System Daemon
     Loaded: loaded (/etc/systemd/system/rtorrent.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Thu 2021-05-27 10:12:26 EEST; 2s ago
    Process: 22855 ExecStartPre=/bin/rm -f /home/rtorrent/.session/rtorrent.lock (code=exited, status=0/SUCCESS)
    Process: 22856 ExecStart=/usr/bin/rtorrent -o import=/home/rtorrent/.rtorrent.rc (code=exited, status=255/EXCEPTION)
   Main PID: 22856 (code=exited, status=255/EXCEPTION)
Why is this happening? What I am doing wrong? **UPDATE 2:** One more thing, This post suggest not dropping any files in the /etc/systemd/system/, but instead, to drop them in /usr/local/lib/systemd/system which in Debian based systems is in /lib/systemd/system. Therefore, I moved the unit-file there and when enabling it, it automatically created a symlink to /etc/systemd/system/. But still,, I get this error:
$ sudo systemctl status rtorrent
● rtorrent.service - rTorrent System Daemon
     Loaded: loaded (/lib/systemd/system/rtorrent.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Thu 2021-05-27 10:39:14 EEST; 924ms ago
    Process: 24530 ExecStartPre=/bin/rm -f /home/rtorrent/.session/rtorrent.lock (code=exited, status=0/SUCCESS)
    Process: 24531 ExecStart=/usr/bin/rtorrent -o import=/home/rtorrent/.rtorrent.rc (code=exited, status=255/EXCEPTION)
   Main PID: 24531 (code=exited, status=255/EXCEPTION)
Asked by techsk8 (703 rep)
May 27, 2021, 06:13 AM
Last activity: Mar 12, 2025, 06:48 AM