rakshasa / rtorrent

rTorrent BitTorrent client
https://github.com/rakshasa/rtorrent/wiki
GNU General Public License v2.0
4.05k stars 412 forks source link

Cannot figure out Daemon Mode #949

Open nfettinger opened 4 years ago

nfettinger commented 4 years ago

I am trying to configure RTorrent to run as a service without screen/xterm/etc I am using the new system.daemon = true flag in the .rc configuration file (as well as in ExecStart= with -o), however it is not making any difference.

rTorrent 0.9.8/0.13.8

journalctl -xe entry:

-- Unit rtorrent.service has begun starting up.
Jan 04 01:52:02 alfred rtorrent[30660]: Error opening terminal: unknown.
Jan 04 01:52:02 alfred systemd[1]: rtorrent.service: Control process exited, code=exited status=1
Jan 04 01:52:02 alfred systemd[1]: rtorrent.service: Failed with result 'exit-code'.
Jan 04 01:52:02 alfred systemd[1]: Failed to start rtorrent.
-- Subject: Unit rtorrent.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
Antorell commented 4 years ago

Try "system.daemon.set = true", it's the setting I use with the latest git and rtorrent loads as a daemon without issue running as a systemd service.

roberth1990 commented 4 years ago
[Unit]
Description=rTorrent
After=network.target

[Service]
Type=simple
User=1000
Group=1000
KillMode=none
# Modify the next line to the absolute path for rtorrent.lock, for example
ExecStartPre=-/bin/rm -f /home/roberth/rtorrent/work/rtorrent.lock
ExecStart=/usr/bin/rtorrent -o system.daemon.set=true
ExecStop=/bin/kill -9 $MAINPID
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

This one is working for me, just remember to change user, paths etc to correspond to your setup. I use the daemon mode.

Antorell commented 4 years ago

You don't need ExecStop=/bin/kill -9 $MAINPID, systemd kills the service on its own without issues using KillMode=process. Also restart should be set to "on-failure", so systemd only restarts rtorrent when the service crashes. You can also limit the number of time the service restarts in the Unit like, [Unit] StartLimitInterval=200 StartLimitBurst=6

My systemd looks like this and I've never had any issue with it in 2~3 years: system.daemon.set=true goes first line in rtorrent.rc

[Unit] Description=rtorrent daemon Wants=network.target After=network.target StartLimitInterval=200 StartLimitBurst=6

[Service] Type=simple KillMode=process Restart=on-failure RestartSec=30 User= Group= ExecStartPre=-/bin/rm -f //rtorrent.lock ExecStart=/usr/local/bin/rtorrent WorkingDirectory=/home/rtorrent user dir/ PrivateTmp=no

[Install] WantedBy=multi-user.target

source: https://www.freedesktop.org/software/systemd/man/systemd.service.html

nfettinger commented 4 years ago

Can someone clear up the versions when each of these should be used? system.daemon=true vs system.daemon.set=true

There are several examples of each being used, but without an adequate level of documentation to discern one from the other.

Antorell commented 4 years ago

https://github.com/rakshasa/rtorrent/blob/f37dd0d5c238dc1d7d4739c64680b592dbd5e72f/doc/rtorrent.rc-example

# Run the rTorrent process as a daemon in the background
# (and control via XMLRPC sockets)
#system.daemon.set = true
#network.scgi.open_local = (cat,(session.path),rtorrent.sock)
#execute.nothrow = chmod,770,(cat,(session.path),rtorrent.sock)

https://github.com/rakshasa/rtorrent/blob/f37dd0d5c238dc1d7d4739c64680b592dbd5e72f/doc/rtorrent.rc

# Run rTorrent as a daemon, controlled via XMLRPC.
#
#system.daemon.set = false

https://github.com/rakshasa/rtorrent/search?q=system.daemon.set&unscoped_q=system.daemon.set

kannibalox commented 4 years ago

As with (almost) all $command/$command.set pairs, the former returns the current setting, while the latter allows you to change it. As such, system.daemon=true doesn't actually change anything, the true just gets ignored.

mirolm commented 4 years ago

There is no need to delete rtorrent.lock if you set in config:

session.use_lock.set = no

My systemd service is:

cat rtorrent@.service

[Unit]
Description=rTorrent
After=network-online.target local-fs.target

[Service]
Type=simple
KillMode=process
User=%I
PIDFile=/run/rtorrent.pid
ExecStart=/usr/local/bin/rtorrent -n -o import=/home/%I/.rtorrent.rc
LimitNOFILE=8192

[Install]
WantedBy=multi-user.target

You can enable it with:

systemctl enable rtorrent@user.service

Antorell commented 4 years ago

That setting is good if you want/don't care about multiples instances. My rtorrent is on a seedbox, and I don't want to worry about someone/something else other than systemd starting another rtorrent session/process on the same user.

pyroscope commented 4 years ago

The proper way to handle stale locks is this:

https://github.com/pyroscope/pimp-my-box/blob/master/roles/rtorrent-ps/templates/rtps.service#L43