Skip to content

Commit

Permalink
rTorrent: Allow linux screen launch
Browse files Browse the repository at this point in the history
This pull requests add the `RT_DAEMON_MODE` environment variable which allows the user to configure how rTorrent is launched.

rTorrent is still launched in daemon mode by default unless the user changes it. When daemon mode is disabled, rTorrent will launch in the foreground on a linux screen instead.

This has some graceful exit benefits in limited circumstances. See crazy-max#311
  • Loading branch information
stickz committed Jan 4, 2024
1 parent 964647a commit 811d728
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ RUN apk --update --no-cache add \
php82-zip \
python3 \
py3-pip \
screen \
shadow \
sox \
tar \
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ___
* [WAN IP address](#wan-ip-address)
* [Configure rTorrent session saving](#configure-rtorrent-session-saving)
* [Configure rTorrent tracker scrape](#rtorrent-tracker-scrape-patch)
* [Configure rTorrent launch mode](#rtorrent-launch-mode)
* [Upgrade](#upgrade)
* [Contributing](#contributing)
* [License](#license)
Expand Down Expand Up @@ -139,6 +140,7 @@ Image: crazymax/rtorrent-rutorrent:latest
* `RT_TRACKER_DELAY_SCRAPE`: Delay tracker announces at startup (default `true`)
* `RT_DHT_PORT`: DHT UDP port (`dht.port.set`, default `6881`)
* `RT_INC_PORT`: Incoming connections (`network.port_range.set`, default `50000`)
* `RT_DAEMON_MODE`: Run rTorrent in daemon mode (default `true`)

### ruTorrent

Expand Down Expand Up @@ -355,6 +357,13 @@ The default value is `true`. There are two main benefits to keeping this feature
1) Software Stability: rTorrent will not crash or time-out with tens of thousands of trackers.
2) Immediate Access: ruTorrent can be accessed immediately after rTorrent is started.

## rTorrent launch mode
`RT_DAEMON_MODE` when set to `true` will run rTorrent in the background using daemon mode.
The default value is true for daemon mode. This will disable the rTorrent ncurses interface.

`RT_DAEMON_MODE` when set to `false` will run rTorrent in the foreground using a linux screen.
The name of the linux screen is `rtorrent`. This feature may be required for graceful exit.

## Upgrade

To upgrade, pull the newer image and launch the container:
Expand Down
1 change: 1 addition & 0 deletions rootfs/etc/cont-init.d/03-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ RT_LOG_EXECUTE=${RT_LOG_EXECUTE:-false}
RT_LOG_XMLRPC=${RT_LOG_XMLRPC:-false}
RT_SESSION_SAVE_SECONDS=${RT_SESSION_SAVE_SECONDS:-3600}
RT_TRACKER_DELAY_SCRAPE=${RT_TRACKER_DELAY_SCRAPE:-true}
RT_DAEMON_MODE=${RT_DAEMON_MODE:-true}

RU_REMOVE_CORE_PLUGINS=${RU_REMOVE_CORE_PLUGINS:-httprpc}
RU_HTTP_USER_AGENT=${RU_HTTP_USER_AGENT:-Mozilla/5.0 (Windows NT 6.0; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0}
Expand Down
10 changes: 6 additions & 4 deletions rootfs/etc/cont-init.d/04-create-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ cat > /etc/services.d/rtorrent/run <<EOL
with-contenv
/bin/export HOME /data/rtorrent
/bin/export PWD /data/rtorrent
s6-setuidgid ${PUID}:${PGID}
EOL
if [ -z "${WAN_IP}" ]; then
echo "rtorrent -D -o import=/etc/rtorrent/.rtlocal.rc" >> /etc/services.d/rtorrent/run

[[ -z "${WAN_IP}" ]] && wan="" || wan="-i ${WAN_IP}"
if [ "$RT_DAEMON_MODE" = false ]; then
echo "screen -D -m -S rtorrent s6-setuidgid ${PUID}:${PGID} rtorrent -D -o import=/etc/rtorrent/.rtlocal.rc ${wan}" >> /etc/services.d/rtorrent/run
else
echo "rtorrent -D -o import=/etc/rtorrent/.rtlocal.rc -i ${WAN_IP}" >> /etc/services.d/rtorrent/run
echo "s6-setuidgid ${PUID}:${PGID}" >> /etc/services.d/rtorrent/run
echo "rtorrent -D -o import=/etc/rtorrent/.rtlocal.rc ${wan}" >> /etc/services.d/rtorrent/run
fi

chmod +x /etc/services.d/rtorrent/run
2 changes: 1 addition & 1 deletion rootfs/tpls/etc/rtorrent/.rtlocal.rc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Launch as a daemon
system.daemon.set = true
system.daemon.set = @RT_DAEMON_MODE@

# Instance layout
method.insert = cfg.basedir, private|const|string, (cat,"/data/rtorrent/")
Expand Down
1 change: 1 addition & 0 deletions test/rtorrent-rutorrent.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ WEBDAV_AUTHBASIC_STRING=WebDAV restricted access
RT_LOG_LEVEL=info
RT_LOG_EXECUTE=false
RT_LOG_XMLRPC=false
RT_DAEMON_MODE=true

RU_REMOVE_CORE_PLUGINS=httprpc
RU_HTTP_USER_AGENT=Mozilla/5.0 (Windows NT 6.0; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Expand Down

0 comments on commit 811d728

Please sign in to comment.