2

Im having troubleshooting configuring systemd with rtorrent and screen in my raspberry pi.

I have the service unit file configured and when i start it manually with systemctl start rtorrent it starts successfully, but the problem is that the service fail to start on reboot, so i have to manually start it always.

Of course, I have enabled the service with systemctl enable rtorrent

Here the service unit definition:

[Unit]
Description=rTorrent
After=network.target

[Service]
Type=forking
User=rtorrent
Group=rtorrent
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=/home/rtorrent/
Restart=on-failure

[Install]
WantedBy=network-online.target

On boot there is the systemctl status rtorrent output

● rtorrent.service - rTorrent
   Loaded: loaded (/etc/systemd/system/rtorrent.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2020-01-04 16:51:20 GMT; 1min 0s ago
  Process: 567 ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/bin/rtorrent (code=exited, status=0/SUCCESS)
  Process: 571 ExecStop=/usr/bin/killall -w -s 2 /usr/bin/rtorrent (code=exited, status=1/FAILURE)
 Main PID: 568 (code=exited, status=0/SUCCESS)

Jan 04 16:51:20 raspberry systemd[1]: rtorrent.service: Service RestartSec=100ms expired, scheduling restart.
Jan 04 16:51:20 raspberry systemd[1]: rtorrent.service: Scheduled restart job, restart counter is at 5.
Jan 04 16:51:20 raspberry systemd[1]: Stopped rTorrent.
Jan 04 16:51:20 raspberry systemd[1]: rtorrent.service: Start request repeated too quickly.
Jan 04 16:51:20 raspberry systemd[1]: rtorrent.service: Failed with result 'exit-code'.
Jan 04 16:51:20 raspberry systemd[1]: Failed to start rTorrent.

And here the journalctl --unit=rtorrent output

Jan 04 16:51:19 raspberry killall[571]: /usr/bin/rtorrent: no process found
Jan 04 16:51:19 raspberry systemd[1]: rtorrent.service: Control process exited, code=exited, status=1/FAILURE
Jan 04 16:51:19 raspberry systemd[1]: rtorrent.service: Failed with result 'exit-code'.
Jan 04 16:51:20 raspberry systemd[1]: rtorrent.service: Service RestartSec=100ms expired, scheduling restart.
Jan 04 16:51:20 raspberry systemd[1]: rtorrent.service: Scheduled restart job, restart counter is at 5.
Jan 04 16:51:20 raspberry systemd[1]: Stopped rTorrent.
Jan 04 16:51:20 raspberry systemd[1]: rtorrent.service: Start request repeated too quickly.
Jan 04 16:51:20 raspberry systemd[1]: rtorrent.service: Failed with result 'exit-code'.
Jan 04 16:51:20 raspberry systemd[1]: Failed to start rTorrent.
Jan 04 16:52:27 raspberry systemd[1]: Starting rTorrent...
Jan 04 16:52:27 raspberry systemd[1]: Started rTorrent.

It says that the rtorrent binary cannot be found, but it exists

-rwxr-xr-x 1 rtorrent rtorrent 1134120 Jun 28  2018 /usr/bin/rtorrent

and if i run systemctl start rtorrent it start succesfully

● rtorrent.service - rTorrent
   Loaded: loaded (/etc/systemd/system/rtorrent.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-01-04 16:52:27 GMT; 8min ago
  Process: 924 ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/bin/rtorrent (code=exited, status=0/SUCCESS)
 Main PID: 925 (screen)
    Tasks: 4 (limit: 2200)
   Memory: 4.7M
   CGroup: /system.slice/rtorrent.service
           ├─925 /usr/bin/SCREEN -d -m -fa -S rtorrent /usr/bin/rtorrent
           └─926 /usr/bin/rtorrent

Jan 04 16:52:27 raspberry systemd[1]: Starting rTorrent...
Jan 04 16:52:27 raspberry systemd[1]: Started rTorrent.

I've also found that if i change the "User=pi" its starts on boot, but the process run with the pi user and i dont want it...

If i start it manually the process is executed by the rtorrent user, its what i want on boot :S

rtorrent   925  0.0  0.2   8132  2104 ?        Ss   16:52   0:00 /usr/bin/SCREEN -d -m -fa -S rtorrent /usr/bin/rtorrent
rtorrent   926  0.1  1.5  85136 14596 pts/1    Ssl+ 16:52   0:00 /usr/bin/rtorrent
6
  • It says that the process rtorrent was not found. Is it not 100 ms which is the problem? The process might take longer to start during boot.
    – Cheiron
    Commented Jan 4, 2020 at 20:01
  • "It says that the rtorrent binary cannot be found" -> No. As per previous comment, it's killall saying it could not find any process with that name to kill. It does check that a corresponding binary exists first, and if it doesn't, says "No such file or directory", not "no process found".
    – goldilocks
    Commented Jan 4, 2020 at 21:12
  • Yep it seems that the process fails on boot.. But why? How can i debug it? When i start it manually it works fine.
    – codek
    Commented Jan 4, 2020 at 22:48
  • Why do you want to run rtorrent in a screen? This complicated things a lot in particular if you detach it (forking). If rtorrent finishes its output within screen is also lost. That's why you don't see any (error) messages from rtorrent. Is it possible to just redirect its output to omit using screen? Please address me with @Ingo, otherwise I won't see your reply.
    – Ingo
    Commented Jan 6, 2020 at 19:40
  • @Ingo thank you for your answer! Really i dont know why i want run it with screen, i just followed a guide. But i think that can be interesting to be able to attach the screen that is runing the rtorrent and interact with it. Anyway i will do some tests without screen, to see if I'm able to see the error. If you have some suggestion, i will appreciate it :) Thanks again!!
    – codek
    Commented Jan 7, 2020 at 19:24

2 Answers 2

1

According to apt show rtorrent you will find:

rtorrent is a BitTorrent client based on LibTorrent. It uses ncurses and aims to be a lean, yet powerful BitTorrent client, with features similar to the most complex graphical clients.

Since it is a terminal application, it can be used with the "screen"/"dtach" utility so that the user can conveniently logout from the system while keeping the file transfers active.

I haven't used it before but for my undertanding it is an interactive program. systemd is used to manage non interactive services in the background so it seems not to be the right solution for your problem. You should consider to start the program just when you need it to manage BitTorrent.

0
1

I use rtorrent as a non-interactive tool. I just copy *.torrent files into a directory and rtorrent automtically picks them up for download/upload.

I use tmux and rtorrent (not screen) on Ubuntu 19.10 (if that matters)

[Unit]
Description=rTorrent
Documentation=https://github.com/rakshasa/rtorrent
After=network.target local-fs.target

[Service]
Type=forking
KillMode=none
User=ubuntu
ExecStart=/usr/bin/tmux -S /tmp/rtorrent.sock new-session -d -s rtorrent 'rtorrent -n -O import=/home/ubuntu/.rtorrent.rc'
ExecStop=/usr/bin/tmux -S /tmp/rtorrent.sock send-keys -t rtorrent C-q
WorkingDirectory=/home/ubuntu

[Install]
WantedBy=default.target

After reboot I can attach to tmux with this command and see the progress of downloads and uploads:

tmux  -S /tmp/rtorrent.sock at -t rtorrent

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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