Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot figure out Daemon Mode #949

Open
nfettinger opened this issue Jan 4, 2020 · 9 comments
Open

Cannot figure out Daemon Mode #949

nfettinger opened this issue Jan 4, 2020 · 9 comments

Comments

@nfettinger
Copy link

nfettinger commented Jan 4, 2020

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
Copy link

Antorell commented Jan 4, 2020

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
Copy link

roberth1990 commented Jan 7, 2020

[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
Copy link

Antorell commented Jan 7, 2020

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 folder>/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
Copy link
Author

nfettinger commented Jan 8, 2020

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
Copy link

Antorell commented Jan 8, 2020

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
Copy link
Contributor

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
Copy link

mirolm commented Jan 9, 2020

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

session.use_lock.set = no

My systemd service is:

cat [email protected]

[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 [email protected]

@Antorell
Copy link

Antorell commented Jan 9, 2020

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants