socker backend support
This commit is contained in:
@@ -220,3 +220,20 @@ PYTORRENT_DEBUG_INSTALL=1
|
||||
```
|
||||
|
||||
On RHEL-compatible systems the installer also tries to enable CRB/PowerTools and installs `libcurl-devel`, `redhat-rpm-config`, `patch`, `diffutils`, `findutils`, `file`, and `libstdc++-devel`, because minimal Alma/Rocky images often do not include enough build tooling.
|
||||
|
||||
### SCGI TCP vs Unix socket
|
||||
|
||||
Default stack mode remains TCP:
|
||||
|
||||
```bash
|
||||
network.scgi.open_port = 127.0.0.1:5000
|
||||
```
|
||||
|
||||
Socket mode is opt-in:
|
||||
|
||||
```bash
|
||||
sudo bash scripts/install_stack.sh --scgi-unix-socket
|
||||
sudo bash scripts/install_stack.sh --rtorrent-socket /run/rtorrent/rtorrent.sock
|
||||
```
|
||||
|
||||
Socket mode writes `network.scgi.open_local`, installs `rtorrent-scgi-proxy`, points pyTorrent at the proxy URL and grants the proxy user access to the rTorrent socket group.
|
||||
|
||||
@@ -543,7 +543,10 @@ def install_symlinks(rtorrent_install, libtorrent_install, xmlrpc_install=None,
|
||||
run(["ldconfig"], debug=debug)
|
||||
|
||||
|
||||
def write_service(service_path, binary_path, runtime_lib_dirs):
|
||||
def write_service(service_path, binary_path, runtime_lib_dirs, *, runtime_directory=None):
|
||||
runtime_directory_lines = ""
|
||||
if runtime_directory:
|
||||
runtime_directory_lines = f"RuntimeDirectory={runtime_directory}\nRuntimeDirectoryMode=0750\n"
|
||||
service_content = f"""[Unit]
|
||||
Description=rTorrent for %I | https://git.linuxiarz.pl/gru/tools_scripts/_edit/master/install_rtorrent.py
|
||||
After=network.target
|
||||
@@ -561,7 +564,7 @@ TimeoutStopSec=300
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
LimitNOFILE=1048576
|
||||
Environment=LD_LIBRARY_PATH={runtime_lib_dirs}
|
||||
{runtime_directory_lines}Environment=LD_LIBRARY_PATH={runtime_lib_dirs}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -586,7 +589,11 @@ def rtorrent_bind_address_directive(rtorrent_ref, rtorrent_version=None):
|
||||
return "network.bind_address.set"
|
||||
return "network.bind_address.ipv4.set"
|
||||
|
||||
def build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive):
|
||||
def build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive, scgi_backend="tcp", scgi_socket="/run/rtorrent/rtorrent.sock"):
|
||||
if scgi_backend == "unix":
|
||||
scgi_line = f"network.scgi.open_local = {scgi_socket}\nexecute.nothrow = chmod,660,{scgi_socket}"
|
||||
else:
|
||||
scgi_line = f"network.scgi.open_port = 127.0.0.1:{scgi_port}"
|
||||
return f"""
|
||||
## https://git.linuxiarz.pl/gru/tools_scripts/_edit/master/install_rtorrent.py
|
||||
# Generated by install_rtorrent.py
|
||||
@@ -595,7 +602,7 @@ directory.default.set = /home/{username}/downloads
|
||||
session.path.set = /home/{username}/.session
|
||||
encoding.add = UTF-8
|
||||
|
||||
network.scgi.open_port = 127.0.0.1:{scgi_port}
|
||||
{scgi_line}
|
||||
network.port_range.set = {torrent_port}-{torrent_port}
|
||||
network.port_random.set = no
|
||||
{bind_address_directive} = 0.0.0.0
|
||||
@@ -639,9 +646,9 @@ pieces.hash.on_completion.set = 0
|
||||
#pieces.memory.max.set = 1024M
|
||||
""".lstrip()
|
||||
|
||||
def write_rtorrent_config(user_home, username, scgi_port, torrent_port, bind_address_directive, *, force_config=False):
|
||||
def write_rtorrent_config(user_home, username, scgi_port, torrent_port, bind_address_directive, *, scgi_backend="tcp", scgi_socket="/run/rtorrent/rtorrent.sock", force_config=False):
|
||||
config_path = Path(user_home) / ".rtorrent.rc"
|
||||
config_content = build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive)
|
||||
config_content = build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive, scgi_backend=scgi_backend, scgi_socket=scgi_socket)
|
||||
|
||||
if config_path.exists() and not force_config:
|
||||
print(f"Config already exists: {config_path}")
|
||||
@@ -815,7 +822,9 @@ def build_parser():
|
||||
parser.add_argument("--user", default=DEFAULT_USER, help=f"System user for the service (default: {DEFAULT_USER})")
|
||||
parser.add_argument("--group", default=DEFAULT_GROUP, help=f"System group for the service (default: {DEFAULT_GROUP})")
|
||||
parser.add_argument("--home", default=DEFAULT_HOME, help=f"Home directory for the service user (default: {DEFAULT_HOME})")
|
||||
parser.add_argument("--scgi-port", type=int, default=DEFAULT_SCGI_PORT, help=f"SCGI listen port for rTorrent XMLRPC/SCGI (default: {DEFAULT_SCGI_PORT})")
|
||||
parser.add_argument("--scgi-port", type=int, default=DEFAULT_SCGI_PORT, help=f"SCGI TCP listen port for rTorrent XMLRPC/SCGI (default: {DEFAULT_SCGI_PORT})")
|
||||
parser.add_argument("--scgi-backend", choices=["tcp", "unix"], default=os.getenv("RTORRENT_SCGI_BACKEND", "tcp"), help="rTorrent SCGI backend to write in .rtorrent.rc (default: tcp).")
|
||||
parser.add_argument("--scgi-socket", default=os.getenv("RTORRENT_SCGI_SOCKET", "/run/rtorrent/rtorrent.sock"), help="Unix socket path used when --scgi-backend unix is selected.")
|
||||
parser.add_argument("--torrent-port", type=int, default=DEFAULT_TORRENT_PORT, help=f"Incoming BitTorrent listen port (default: {DEFAULT_TORRENT_PORT})")
|
||||
parser.add_argument("--force-config", action="store_true", help="Overwrite existing ~/.rtorrent.rc. By default, existing config is left unchanged and the proposed changes are printed.")
|
||||
parser.add_argument("--only-build", action="store_true", help="Only build and install libtorrent/rTorrent under /opt. Skip user, config and systemd.")
|
||||
@@ -877,7 +886,10 @@ def main():
|
||||
print(" - skip service user, config and systemd setup")
|
||||
else:
|
||||
print(f" - configure systemd service for user '{args.user}'")
|
||||
print(f" - use SCGI port {args.scgi_port} and torrent port {args.torrent_port}")
|
||||
if args.scgi_backend == "unix":
|
||||
print(f" - use SCGI Unix socket {args.scgi_socket} and torrent port {args.torrent_port}")
|
||||
else:
|
||||
print(f" - use SCGI port {args.scgi_port} and torrent port {args.torrent_port}")
|
||||
|
||||
if not prompt_yes_no("Continue?", default=True, assume_yes=args.yes):
|
||||
print("Aborted by user.")
|
||||
@@ -916,7 +928,7 @@ def main():
|
||||
prepare_user_dirs(args.home, args.user)
|
||||
bind_address_directive = rtorrent_bind_address_directive(args.rtorrent_ref, rtorrent_version)
|
||||
print(f"Using rTorrent bind address directive: {bind_address_directive}")
|
||||
write_rtorrent_config(args.home, args.user, args.scgi_port, args.torrent_port, bind_address_directive, force_config=args.force_config)
|
||||
write_rtorrent_config(args.home, args.user, args.scgi_port, args.torrent_port, bind_address_directive, scgi_backend=args.scgi_backend, scgi_socket=args.scgi_socket, force_config=args.force_config)
|
||||
runtime_lib_dirs = [f"{libtorrent_install}/lib"]
|
||||
if args.rpc_backend == "xmlrpc-c" and xmlrpc_install:
|
||||
runtime_lib_dirs.append(f"{xmlrpc_install}/lib")
|
||||
@@ -924,7 +936,12 @@ def main():
|
||||
runtime_lib_dirs.append(f"{curl_install}/lib")
|
||||
if cares_install:
|
||||
runtime_lib_dirs.append(f"{cares_install}/lib")
|
||||
write_service(DEFAULT_SERVICE_PATH, "/usr/local/bin/rtorrent", ":".join(runtime_lib_dirs))
|
||||
runtime_directory = None
|
||||
if args.scgi_backend == "unix" and args.scgi_socket.startswith("/run/"):
|
||||
parts = Path(args.scgi_socket).parts
|
||||
if len(parts) >= 3:
|
||||
runtime_directory = parts[2]
|
||||
write_service(DEFAULT_SERVICE_PATH, "/usr/local/bin/rtorrent", ":".join(runtime_lib_dirs), runtime_directory=runtime_directory)
|
||||
enable_service(args.user, debug=args.debug)
|
||||
print(f"\nService status hint: systemctl status rtorrent@{args.user}.service")
|
||||
|
||||
|
||||
@@ -536,7 +536,10 @@ def install_symlinks(rtorrent_install, libtorrent_install, xmlrpc_install=None,
|
||||
run(["ldconfig"], debug=debug)
|
||||
|
||||
|
||||
def write_service(service_path, binary_path, runtime_lib_dirs):
|
||||
def write_service(service_path, binary_path, runtime_lib_dirs, *, runtime_directory=None):
|
||||
runtime_directory_lines = ""
|
||||
if runtime_directory:
|
||||
runtime_directory_lines = f"RuntimeDirectory={runtime_directory}\nRuntimeDirectoryMode=0750\n"
|
||||
service_content = f"""[Unit]
|
||||
Description=rTorrent for %I | https://git.linuxiarz.pl/gru/tools_scripts/_edit/master/install_rtorrent.py
|
||||
After=network.target
|
||||
@@ -554,7 +557,7 @@ TimeoutStopSec=300
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
LimitNOFILE=1048576
|
||||
Environment=LD_LIBRARY_PATH={runtime_lib_dirs}
|
||||
{runtime_directory_lines}Environment=LD_LIBRARY_PATH={runtime_lib_dirs}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -579,7 +582,11 @@ def rtorrent_bind_address_directive(rtorrent_ref, rtorrent_version=None):
|
||||
return "network.bind_address.set"
|
||||
return "network.bind_address.ipv4.set"
|
||||
|
||||
def build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive):
|
||||
def build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive, scgi_backend="tcp", scgi_socket="/run/rtorrent/rtorrent.sock"):
|
||||
if scgi_backend == "unix":
|
||||
scgi_line = f"network.scgi.open_local = {scgi_socket}\nexecute.nothrow = chmod,660,{scgi_socket}"
|
||||
else:
|
||||
scgi_line = f"network.scgi.open_port = 127.0.0.1:{scgi_port}"
|
||||
return f"""
|
||||
## https://git.linuxiarz.pl/gru/tools_scripts/_edit/master/install_rtorrent.py
|
||||
# Generated by install_rtorrent.py
|
||||
@@ -588,7 +595,7 @@ directory.default.set = /home/{username}/downloads
|
||||
session.path.set = /home/{username}/.session
|
||||
encoding.add = UTF-8
|
||||
|
||||
network.scgi.open_port = 127.0.0.1:{scgi_port}
|
||||
{scgi_line}
|
||||
network.port_range.set = {torrent_port}-{torrent_port}
|
||||
network.port_random.set = no
|
||||
{bind_address_directive} = 0.0.0.0
|
||||
@@ -633,9 +640,9 @@ pieces.hash.on_completion.set = 0
|
||||
""".lstrip()
|
||||
|
||||
|
||||
def write_rtorrent_config(user_home, username, scgi_port, torrent_port, bind_address_directive, *, force_config=False):
|
||||
def write_rtorrent_config(user_home, username, scgi_port, torrent_port, bind_address_directive, *, scgi_backend="tcp", scgi_socket="/run/rtorrent/rtorrent.sock", force_config=False):
|
||||
config_path = Path(user_home) / ".rtorrent.rc"
|
||||
config_content = build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive)
|
||||
config_content = build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive, scgi_backend=scgi_backend, scgi_socket=scgi_socket)
|
||||
|
||||
if config_path.exists() and not force_config:
|
||||
print(f"Config already exists: {config_path}")
|
||||
@@ -809,7 +816,9 @@ def build_parser():
|
||||
parser.add_argument("--user", default=DEFAULT_USER, help=f"System user for the service (default: {DEFAULT_USER})")
|
||||
parser.add_argument("--group", default=DEFAULT_GROUP, help=f"System group for the service (default: {DEFAULT_GROUP})")
|
||||
parser.add_argument("--home", default=DEFAULT_HOME, help=f"Home directory for the service user (default: {DEFAULT_HOME})")
|
||||
parser.add_argument("--scgi-port", type=int, default=DEFAULT_SCGI_PORT, help=f"SCGI listen port for rTorrent XMLRPC/SCGI (default: {DEFAULT_SCGI_PORT})")
|
||||
parser.add_argument("--scgi-port", type=int, default=DEFAULT_SCGI_PORT, help=f"SCGI TCP listen port for rTorrent XMLRPC/SCGI (default: {DEFAULT_SCGI_PORT})")
|
||||
parser.add_argument("--scgi-backend", choices=["tcp", "unix"], default=os.getenv("RTORRENT_SCGI_BACKEND", "tcp"), help="rTorrent SCGI backend to write in .rtorrent.rc (default: tcp).")
|
||||
parser.add_argument("--scgi-socket", default=os.getenv("RTORRENT_SCGI_SOCKET", "/run/rtorrent/rtorrent.sock"), help="Unix socket path used when --scgi-backend unix is selected.")
|
||||
parser.add_argument("--torrent-port", type=int, default=DEFAULT_TORRENT_PORT, help=f"Incoming BitTorrent listen port (default: {DEFAULT_TORRENT_PORT})")
|
||||
parser.add_argument("--force-config", action="store_true", help="Overwrite existing ~/.rtorrent.rc. By default, existing config is left unchanged and the proposed changes are printed.")
|
||||
parser.add_argument("--only-build", action="store_true", help="Only build and install libtorrent/rTorrent under /opt. Skip user, config and systemd.")
|
||||
@@ -861,7 +870,10 @@ def main():
|
||||
print(" - skip service user, config and systemd setup")
|
||||
else:
|
||||
print(f" - configure systemd service for user '{args.user}'")
|
||||
print(f" - use SCGI port {args.scgi_port} and torrent port {args.torrent_port}")
|
||||
if args.scgi_backend == "unix":
|
||||
print(f" - use SCGI Unix socket {args.scgi_socket} and torrent port {args.torrent_port}")
|
||||
else:
|
||||
print(f" - use SCGI port {args.scgi_port} and torrent port {args.torrent_port}")
|
||||
|
||||
if not prompt_yes_no("Continue?", default=True, assume_yes=args.yes):
|
||||
print("Aborted by user.")
|
||||
@@ -900,7 +912,7 @@ def main():
|
||||
prepare_user_dirs(args.home, args.user)
|
||||
bind_address_directive = rtorrent_bind_address_directive(args.rtorrent_ref, rtorrent_version)
|
||||
print(f"Using rTorrent bind address directive: {bind_address_directive}")
|
||||
write_rtorrent_config(args.home, args.user, args.scgi_port, args.torrent_port, bind_address_directive, force_config=args.force_config)
|
||||
write_rtorrent_config(args.home, args.user, args.scgi_port, args.torrent_port, bind_address_directive, scgi_backend=args.scgi_backend, scgi_socket=args.scgi_socket, force_config=args.force_config)
|
||||
runtime_lib_dirs = [f"{libtorrent_install}/lib"]
|
||||
if args.rpc_backend == "xmlrpc-c" and xmlrpc_install:
|
||||
runtime_lib_dirs.append(f"{xmlrpc_install}/lib")
|
||||
@@ -908,7 +920,12 @@ def main():
|
||||
runtime_lib_dirs.append(f"{curl_install}/lib")
|
||||
if cares_install:
|
||||
runtime_lib_dirs.append(f"{cares_install}/lib")
|
||||
write_service(DEFAULT_SERVICE_PATH, "/usr/local/bin/rtorrent", ":".join(runtime_lib_dirs))
|
||||
runtime_directory = None
|
||||
if args.scgi_backend == "unix" and args.scgi_socket.startswith("/run/"):
|
||||
parts = Path(args.scgi_socket).parts
|
||||
if len(parts) >= 3:
|
||||
runtime_directory = parts[2]
|
||||
write_service(DEFAULT_SERVICE_PATH, "/usr/local/bin/rtorrent", ":".join(runtime_lib_dirs), runtime_directory=runtime_directory)
|
||||
enable_service(args.user, debug=args.debug)
|
||||
print(f"\nService status hint: systemctl status rtorrent@{args.user}.service")
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@ RTORRENT_USER="${RTORRENT_USER:-rtorrent}"
|
||||
RTORRENT_HOME="${RTORRENT_HOME:-/home/${RTORRENT_USER}}"
|
||||
RTORRENT_BASE_DIR="${RTORRENT_BASE_DIR:-/opt/rtorrent_build}"
|
||||
RTORRENT_SCGI_PORT="${RTORRENT_SCGI_PORT:-5000}"
|
||||
RTORRENT_SCGI_BACKEND="${RTORRENT_SCGI_BACKEND:-tcp}"
|
||||
RTORRENT_SCGI_SOCKET="${RTORRENT_SCGI_SOCKET:-/run/rtorrent/rtorrent.sock}"
|
||||
RTORRENT_SCGI_PROXY_LISTEN="${RTORRENT_SCGI_PROXY_LISTEN:-127.0.0.1:5050}"
|
||||
RTORRENT_SCGI_PROXY_TOKEN="${RTORRENT_SCGI_PROXY_TOKEN:-}"
|
||||
RTORRENT_TORRENT_PORT="${RTORRENT_TORRENT_PORT:-51300}"
|
||||
RTORRENT_REF="${RTORRENT_REF:-v0.16.11}"
|
||||
LIBTORRENT_REF="${LIBTORRENT_REF:-v0.16.11}"
|
||||
@@ -25,10 +29,28 @@ PYTORRENT_BASE_URL="${PYTORRENT_BASE_URL:-http://127.0.0.1:${PYTORRENT_PORT}}"
|
||||
PYTORRENT_PROFILE_NAME="${PYTORRENT_PROFILE_NAME:-Local rTorrent}"
|
||||
PYTORRENT_API_TOKEN="${PYTORRENT_API_TOKEN:-}"
|
||||
PYTORRENT_SERVICE_NAME="${PYTORRENT_SERVICE_NAME:-pytorrent}"
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-scgi://127.0.0.1:${RTORRENT_SCGI_PORT}}"
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-}"
|
||||
RTORRENT_BUILD_FROM_SOURCE="${RTORRENT_BUILD_FROM_SOURCE:-0}"
|
||||
RTORRENT_FORCE_CONFIG="${RTORRENT_FORCE_CONFIG:-1}"
|
||||
|
||||
normalize_scgi_settings() {
|
||||
case "${RTORRENT_SCGI_BACKEND}" in
|
||||
tcp|unix) ;;
|
||||
*) echo "Invalid RTORRENT_SCGI_BACKEND: ${RTORRENT_SCGI_BACKEND}" >&2; exit 1 ;;
|
||||
esac
|
||||
if [[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]]; then
|
||||
if [[ -z "${RTORRENT_SCGI_PROXY_TOKEN}" ]]; then
|
||||
RTORRENT_SCGI_PROXY_TOKEN="$(LC_ALL=C tr -dc 'A-Za-z0-9_-' </dev/urandom | head -c 43 || true)"
|
||||
if [[ -z "${RTORRENT_SCGI_PROXY_TOKEN}" ]]; then
|
||||
RTORRENT_SCGI_PROXY_TOKEN="$(date +%s%N)"
|
||||
fi
|
||||
fi
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-scgi://${RTORRENT_SCGI_PROXY_LISTEN}/proxy/${RTORRENT_SCGI_PROXY_TOKEN}}"
|
||||
else
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-scgi://127.0.0.1:${RTORRENT_SCGI_PORT}}"
|
||||
fi
|
||||
}
|
||||
|
||||
RTORRENT_EXTRA_ARGS=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
@@ -36,6 +58,19 @@ while [[ $# -gt 0 ]]; do
|
||||
RTORRENT_BUILD_FROM_SOURCE=1
|
||||
shift
|
||||
;;
|
||||
--scgi-backend)
|
||||
RTORRENT_SCGI_BACKEND="$2"
|
||||
shift 2
|
||||
;;
|
||||
--scgi-unix-socket)
|
||||
RTORRENT_SCGI_BACKEND="unix"
|
||||
shift
|
||||
;;
|
||||
--rtorrent-socket|--scgi-socket)
|
||||
RTORRENT_SCGI_BACKEND="unix"
|
||||
RTORRENT_SCGI_SOCKET="$2"
|
||||
shift 2
|
||||
;;
|
||||
--with-xmlrpc-c)
|
||||
RTORRENT_BUILD_FROM_SOURCE=1
|
||||
RTORRENT_EXTRA_ARGS+=(--with-xmlrpc-c)
|
||||
@@ -43,11 +78,13 @@ while [[ $# -gt 0 ]]; do
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1" >&2
|
||||
echo "Supported options: --build-rtorrent, --with-xmlrpc-c" >&2
|
||||
echo "Supported options: --build-rtorrent, --with-xmlrpc-c, --scgi-backend tcp|unix, --scgi-unix-socket, --rtorrent-socket PATH" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
normalize_scgi_settings
|
||||
|
||||
if [[ "${RTORRENT_WITH_XMLRPC_C:-0}" == "1" ]]; then
|
||||
RTORRENT_BUILD_FROM_SOURCE=1
|
||||
RTORRENT_EXTRA_ARGS+=(--with-xmlrpc-c)
|
||||
@@ -75,12 +112,19 @@ write_rtorrent_config() {
|
||||
echo "Keeping existing config: ${config}"
|
||||
return
|
||||
fi
|
||||
local scgi_line
|
||||
if [[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]]; then
|
||||
scgi_line="network.scgi.open_local = ${RTORRENT_SCGI_SOCKET}
|
||||
execute.nothrow = chmod,660,${RTORRENT_SCGI_SOCKET}"
|
||||
else
|
||||
scgi_line="network.scgi.open_port = 127.0.0.1:${RTORRENT_SCGI_PORT}"
|
||||
fi
|
||||
cat > "${config}" <<EOF_CONFIG
|
||||
directory.default.set = ${RTORRENT_HOME}/downloads
|
||||
session.path.set = ${RTORRENT_HOME}/.session
|
||||
encoding.add = UTF-8
|
||||
|
||||
network.scgi.open_port = 127.0.0.1:${RTORRENT_SCGI_PORT}
|
||||
${scgi_line}
|
||||
network.port_range.set = ${RTORRENT_TORRENT_PORT}-${RTORRENT_TORRENT_PORT}
|
||||
network.port_random.set = no
|
||||
network.bind_address.ipv4.set = 0.0.0.0
|
||||
@@ -124,6 +168,13 @@ EOF_CONFIG
|
||||
}
|
||||
|
||||
write_rtorrent_service() {
|
||||
local runtime_lines=""
|
||||
if [[ "${RTORRENT_SCGI_BACKEND}" == "unix" && "${RTORRENT_SCGI_SOCKET}" == /run/* ]]; then
|
||||
local runtime_dir
|
||||
runtime_dir="$(printf '%s' "${RTORRENT_SCGI_SOCKET}" | cut -d/ -f3)"
|
||||
runtime_lines="RuntimeDirectory=${runtime_dir}
|
||||
RuntimeDirectoryMode=0750"
|
||||
fi
|
||||
cat > /etc/systemd/system/rtorrent@.service <<EOF_SERVICE
|
||||
[Unit]
|
||||
Description=rTorrent for %I
|
||||
@@ -134,6 +185,7 @@ Type=simple
|
||||
User=%I
|
||||
Group=%I
|
||||
KillMode=process
|
||||
${runtime_lines}
|
||||
WorkingDirectory=${RTORRENT_HOME}
|
||||
ExecStartPre=-/bin/rm -f ${RTORRENT_HOME}/.session/rtorrent.lock
|
||||
ExecStart=/usr/bin/rtorrent -o system.daemon.set=true -n -o import=${RTORRENT_HOME}/.rtorrent.rc
|
||||
@@ -169,6 +221,8 @@ if [[ "${RTORRENT_BUILD_FROM_SOURCE}" == "1" ]]; then
|
||||
--group "${RTORRENT_USER}" \
|
||||
--home "${RTORRENT_HOME}" \
|
||||
--scgi-port "${RTORRENT_SCGI_PORT}" \
|
||||
--scgi-backend "${RTORRENT_SCGI_BACKEND}" \
|
||||
--scgi-socket "${RTORRENT_SCGI_SOCKET}" \
|
||||
--torrent-port "${RTORRENT_TORRENT_PORT}" \
|
||||
--rtorrent-ref "${RTORRENT_REF}" \
|
||||
--libtorrent-ref "${LIBTORRENT_REF}"
|
||||
@@ -183,6 +237,14 @@ PYTORRENT_APP_DIR="${PYTORRENT_APP_DIR}" \
|
||||
PYTORRENT_PORT="${PYTORRENT_PORT}" \
|
||||
PYTORRENT_SERVICE_NAME="${PYTORRENT_SERVICE_NAME}" \
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL}" \
|
||||
PYTORRENT_INSTALL_SCGI_PROXY="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo yes || echo no)" \
|
||||
RTORRENT_USER="${RTORRENT_USER}" \
|
||||
RTORRENT_SOCKET="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo "${RTORRENT_SCGI_SOCKET}" || echo "")" \
|
||||
RTORRENT_SCGI_PROXY_TARGET_NETWORK="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo unix || echo tcp)" \
|
||||
RTORRENT_SCGI_PROXY_TARGET_ADDRESS="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo "${RTORRENT_SCGI_SOCKET}" || echo "127.0.0.1:${RTORRENT_SCGI_PORT}")" \
|
||||
RTORRENT_SCGI_PROXY_LISTEN="${RTORRENT_SCGI_PROXY_LISTEN}" \
|
||||
RTORRENT_SCGI_PROXY_TOKEN="${RTORRENT_SCGI_PROXY_TOKEN}" \
|
||||
RTORRENT_SCGI_PROXY_EXTRA_GROUPS="${RTORRENT_USER}" \
|
||||
bash "${PROJECT_DIR}/scripts/install_pytorrent_only.sh" \
|
||||
--yes \
|
||||
--app-dir "${PYTORRENT_APP_DIR}" \
|
||||
|
||||
@@ -18,6 +18,10 @@ RTORRENT_USER="${RTORRENT_USER:-rtorrent}"
|
||||
RTORRENT_HOME="${RTORRENT_HOME:-/home/${RTORRENT_USER}}"
|
||||
RTORRENT_BASE_DIR="${RTORRENT_BASE_DIR:-/opt/rtorrent_build}"
|
||||
RTORRENT_SCGI_PORT="${RTORRENT_SCGI_PORT:-5000}"
|
||||
RTORRENT_SCGI_BACKEND="${RTORRENT_SCGI_BACKEND:-tcp}"
|
||||
RTORRENT_SCGI_SOCKET="${RTORRENT_SCGI_SOCKET:-/run/rtorrent/rtorrent.sock}"
|
||||
RTORRENT_SCGI_PROXY_LISTEN="${RTORRENT_SCGI_PROXY_LISTEN:-127.0.0.1:5050}"
|
||||
RTORRENT_SCGI_PROXY_TOKEN="${RTORRENT_SCGI_PROXY_TOKEN:-}"
|
||||
RTORRENT_TORRENT_PORT="${RTORRENT_TORRENT_PORT:-51300}"
|
||||
RTORRENT_REF="${RTORRENT_REF:-v0.16.11}"
|
||||
LIBTORRENT_REF="${LIBTORRENT_REF:-v0.16.11}"
|
||||
@@ -27,11 +31,42 @@ PYTORRENT_BASE_URL="${PYTORRENT_BASE_URL:-http://127.0.0.1:${PYTORRENT_PORT}}"
|
||||
PYTORRENT_PROFILE_NAME="${PYTORRENT_PROFILE_NAME:-Local rTorrent}"
|
||||
PYTORRENT_API_TOKEN="${PYTORRENT_API_TOKEN:-}"
|
||||
PYTORRENT_SERVICE_NAME="${PYTORRENT_SERVICE_NAME:-pytorrent}"
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-scgi://127.0.0.1:${RTORRENT_SCGI_PORT}}"
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-}"
|
||||
|
||||
normalize_scgi_settings() {
|
||||
case "${RTORRENT_SCGI_BACKEND}" in
|
||||
tcp|unix) ;;
|
||||
*) echo "Invalid RTORRENT_SCGI_BACKEND: ${RTORRENT_SCGI_BACKEND}" >&2; exit 1 ;;
|
||||
esac
|
||||
if [[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]]; then
|
||||
if [[ -z "${RTORRENT_SCGI_PROXY_TOKEN}" ]]; then
|
||||
RTORRENT_SCGI_PROXY_TOKEN="$(LC_ALL=C tr -dc 'A-Za-z0-9_-' </dev/urandom | head -c 43 || true)"
|
||||
if [[ -z "${RTORRENT_SCGI_PROXY_TOKEN}" ]]; then
|
||||
RTORRENT_SCGI_PROXY_TOKEN="$(date +%s%N)"
|
||||
fi
|
||||
fi
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-scgi://${RTORRENT_SCGI_PROXY_LISTEN}/proxy/${RTORRENT_SCGI_PROXY_TOKEN}}"
|
||||
else
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-scgi://127.0.0.1:${RTORRENT_SCGI_PORT}}"
|
||||
fi
|
||||
}
|
||||
|
||||
RTORRENT_EXTRA_ARGS=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--scgi-backend)
|
||||
RTORRENT_SCGI_BACKEND="$2"
|
||||
shift 2
|
||||
;;
|
||||
--scgi-unix-socket)
|
||||
RTORRENT_SCGI_BACKEND="unix"
|
||||
shift
|
||||
;;
|
||||
--rtorrent-socket|--scgi-socket)
|
||||
RTORRENT_SCGI_BACKEND="unix"
|
||||
RTORRENT_SCGI_SOCKET="$2"
|
||||
shift 2
|
||||
;;
|
||||
--with-xmlrpc-c)
|
||||
RTORRENT_EXTRA_ARGS+=(--with-xmlrpc-c)
|
||||
shift
|
||||
@@ -42,6 +77,8 @@ while [[ $# -gt 0 ]]; do
|
||||
;;
|
||||
esac
|
||||
done
|
||||
normalize_scgi_settings
|
||||
|
||||
if [[ "${RTORRENT_WITH_XMLRPC_C:-0}" == "1" ]]; then
|
||||
RTORRENT_EXTRA_ARGS+=(--with-xmlrpc-c)
|
||||
fi
|
||||
@@ -110,36 +147,17 @@ python3 "${SCRIPT_DIR}/install_rtorrent.py" \
|
||||
--group "${RTORRENT_USER}" \
|
||||
--home "${RTORRENT_HOME}" \
|
||||
--scgi-port "${RTORRENT_SCGI_PORT}" \
|
||||
--scgi-backend "${RTORRENT_SCGI_BACKEND}" \
|
||||
--scgi-socket "${RTORRENT_SCGI_SOCKET}" \
|
||||
--torrent-port "${RTORRENT_TORRENT_PORT}" \
|
||||
--rtorrent-ref "${RTORRENT_REF}" \
|
||||
--libtorrent-ref "${LIBTORRENT_REF}"
|
||||
|
||||
cd "${PROJECT_DIR}"
|
||||
bash "${PROJECT_DIR}/scripts/install_debian_ubuntu.sh"
|
||||
PYTORRENT_APP_DIR="${PYTORRENT_APP_DIR}" PYTORRENT_PORT="${PYTORRENT_PORT}" PYTORRENT_SERVICE_NAME="${PYTORRENT_SERVICE_NAME}" PYTORRENT_PROFILE_NAME="${PYTORRENT_PROFILE_NAME}" PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL}" PYTORRENT_INSTALL_SCGI_PROXY="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo yes || echo no)" RTORRENT_USER="${RTORRENT_USER}" RTORRENT_SOCKET="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo "${RTORRENT_SCGI_SOCKET}" || echo "")" RTORRENT_SCGI_PROXY_TARGET_NETWORK="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo unix || echo tcp)" RTORRENT_SCGI_PROXY_TARGET_ADDRESS="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo "${RTORRENT_SCGI_SOCKET}" || echo "127.0.0.1:${RTORRENT_SCGI_PORT}")" RTORRENT_SCGI_PROXY_LISTEN="${RTORRENT_SCGI_PROXY_LISTEN}" RTORRENT_SCGI_PROXY_TOKEN="${RTORRENT_SCGI_PROXY_TOKEN}" RTORRENT_SCGI_PROXY_EXTRA_GROUPS="${RTORRENT_USER}" bash "${PROJECT_DIR}/scripts/install_pytorrent_only.sh" --yes --app-dir "${PYTORRENT_APP_DIR}" --port "${PYTORRENT_PORT}" --service-name "${PYTORRENT_SERVICE_NAME}" --profile-name "${PYTORRENT_PROFILE_NAME}" --scgi-url "${PYTORRENT_RTORRENT_SCGI_URL}"
|
||||
|
||||
if [[ -f "${PYTORRENT_APP_DIR}/.env" ]]; then
|
||||
python3 - "${PYTORRENT_APP_DIR}/.env" <<'PY'
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
import sys
|
||||
path = Path(sys.argv[1])
|
||||
text = path.read_text()
|
||||
if "PYTORRENT_SECRET_KEY=change-me" in text:
|
||||
text = text.replace("PYTORRENT_SECRET_KEY=change-me", "PYTORRENT_SECRET_KEY=" + secrets.token_urlsafe(48))
|
||||
path.write_text(text)
|
||||
PY
|
||||
chown "${PYTORRENT_USER:-pytorrent}:${PYTORRENT_USER:-pytorrent}" "${PYTORRENT_APP_DIR}/.env" || true
|
||||
systemctl restart "${PYTORRENT_SERVICE_NAME}"
|
||||
fi
|
||||
|
||||
CONFIGURE_ARGS=(
|
||||
--base-url "${PYTORRENT_BASE_URL}"
|
||||
--profile-name "${PYTORRENT_PROFILE_NAME}"
|
||||
--scgi-url "${PYTORRENT_RTORRENT_SCGI_URL}"
|
||||
)
|
||||
if [[ -n "${PYTORRENT_API_TOKEN}" ]]; then
|
||||
CONFIGURE_ARGS+=(--api-token "${PYTORRENT_API_TOKEN}")
|
||||
"${PYTORRENT_APP_DIR}/venv/bin/python" "${PYTORRENT_APP_DIR}/scripts/stack_installers/configure_pytorrent_api.py" --base-url "${PYTORRENT_BASE_URL}" --profile-name "${PYTORRENT_PROFILE_NAME}" --scgi-url "${PYTORRENT_RTORRENT_SCGI_URL}" --api-token "${PYTORRENT_API_TOKEN}"
|
||||
fi
|
||||
"${PYTORRENT_APP_DIR}/venv/bin/python" "${PYTORRENT_APP_DIR}/scripts/stack_installers/configure_pytorrent_api.py" "${CONFIGURE_ARGS[@]}"
|
||||
|
||||
echo "Done. pyTorrent: ${PYTORRENT_BASE_URL} | rTorrent SCGI: ${PYTORRENT_RTORRENT_SCGI_URL}"
|
||||
|
||||
@@ -18,6 +18,10 @@ RTORRENT_USER="${RTORRENT_USER:-rtorrent}"
|
||||
RTORRENT_HOME="${RTORRENT_HOME:-/home/${RTORRENT_USER}}"
|
||||
RTORRENT_BASE_DIR="${RTORRENT_BASE_DIR:-/opt/rtorrent_build}"
|
||||
RTORRENT_SCGI_PORT="${RTORRENT_SCGI_PORT:-5000}"
|
||||
RTORRENT_SCGI_BACKEND="${RTORRENT_SCGI_BACKEND:-tcp}"
|
||||
RTORRENT_SCGI_SOCKET="${RTORRENT_SCGI_SOCKET:-/run/rtorrent/rtorrent.sock}"
|
||||
RTORRENT_SCGI_PROXY_LISTEN="${RTORRENT_SCGI_PROXY_LISTEN:-127.0.0.1:5050}"
|
||||
RTORRENT_SCGI_PROXY_TOKEN="${RTORRENT_SCGI_PROXY_TOKEN:-}"
|
||||
RTORRENT_TORRENT_PORT="${RTORRENT_TORRENT_PORT:-51300}"
|
||||
RTORRENT_REF="${RTORRENT_REF:-v0.16.11}"
|
||||
LIBTORRENT_REF="${LIBTORRENT_REF:-v0.16.11}"
|
||||
@@ -27,11 +31,42 @@ PYTORRENT_BASE_URL="${PYTORRENT_BASE_URL:-http://127.0.0.1:${PYTORRENT_PORT}}"
|
||||
PYTORRENT_PROFILE_NAME="${PYTORRENT_PROFILE_NAME:-Local rTorrent}"
|
||||
PYTORRENT_API_TOKEN="${PYTORRENT_API_TOKEN:-}"
|
||||
PYTORRENT_SERVICE_NAME="${PYTORRENT_SERVICE_NAME:-pytorrent}"
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-scgi://127.0.0.1:${RTORRENT_SCGI_PORT}}"
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-}"
|
||||
|
||||
normalize_scgi_settings() {
|
||||
case "${RTORRENT_SCGI_BACKEND}" in
|
||||
tcp|unix) ;;
|
||||
*) echo "Invalid RTORRENT_SCGI_BACKEND: ${RTORRENT_SCGI_BACKEND}" >&2; exit 1 ;;
|
||||
esac
|
||||
if [[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]]; then
|
||||
if [[ -z "${RTORRENT_SCGI_PROXY_TOKEN}" ]]; then
|
||||
RTORRENT_SCGI_PROXY_TOKEN="$(LC_ALL=C tr -dc 'A-Za-z0-9_-' </dev/urandom | head -c 43 || true)"
|
||||
if [[ -z "${RTORRENT_SCGI_PROXY_TOKEN}" ]]; then
|
||||
RTORRENT_SCGI_PROXY_TOKEN="$(date +%s%N)"
|
||||
fi
|
||||
fi
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-scgi://${RTORRENT_SCGI_PROXY_LISTEN}/proxy/${RTORRENT_SCGI_PROXY_TOKEN}}"
|
||||
else
|
||||
PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL:-scgi://127.0.0.1:${RTORRENT_SCGI_PORT}}"
|
||||
fi
|
||||
}
|
||||
|
||||
RTORRENT_EXTRA_ARGS=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--scgi-backend)
|
||||
RTORRENT_SCGI_BACKEND="$2"
|
||||
shift 2
|
||||
;;
|
||||
--scgi-unix-socket)
|
||||
RTORRENT_SCGI_BACKEND="unix"
|
||||
shift
|
||||
;;
|
||||
--rtorrent-socket|--scgi-socket)
|
||||
RTORRENT_SCGI_BACKEND="unix"
|
||||
RTORRENT_SCGI_SOCKET="$2"
|
||||
shift 2
|
||||
;;
|
||||
--with-xmlrpc-c)
|
||||
RTORRENT_EXTRA_ARGS+=(--with-xmlrpc-c)
|
||||
shift
|
||||
@@ -42,6 +77,8 @@ while [[ $# -gt 0 ]]; do
|
||||
;;
|
||||
esac
|
||||
done
|
||||
normalize_scgi_settings
|
||||
|
||||
if [[ "${RTORRENT_WITH_XMLRPC_C:-0}" == "1" ]]; then
|
||||
RTORRENT_EXTRA_ARGS+=(--with-xmlrpc-c)
|
||||
fi
|
||||
@@ -113,21 +150,17 @@ python3 "${SCRIPT_DIR}/install_rtorrent_rhel.py" \
|
||||
--group "${RTORRENT_USER}" \
|
||||
--home "${RTORRENT_HOME}" \
|
||||
--scgi-port "${RTORRENT_SCGI_PORT}" \
|
||||
--scgi-backend "${RTORRENT_SCGI_BACKEND}" \
|
||||
--scgi-socket "${RTORRENT_SCGI_SOCKET}" \
|
||||
--torrent-port "${RTORRENT_TORRENT_PORT}" \
|
||||
--rtorrent-ref "${RTORRENT_REF}" \
|
||||
--libtorrent-ref "${LIBTORRENT_REF}"
|
||||
|
||||
cd "${PROJECT_DIR}"
|
||||
bash "${SCRIPT_DIR}/install_pytorrent_rhel.sh"
|
||||
PYTORRENT_APP_DIR="${PYTORRENT_APP_DIR}" PYTORRENT_PORT="${PYTORRENT_PORT}" PYTORRENT_SERVICE_NAME="${PYTORRENT_SERVICE_NAME}" PYTORRENT_PROFILE_NAME="${PYTORRENT_PROFILE_NAME}" PYTORRENT_RTORRENT_SCGI_URL="${PYTORRENT_RTORRENT_SCGI_URL}" PYTORRENT_INSTALL_SCGI_PROXY="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo yes || echo no)" RTORRENT_USER="${RTORRENT_USER}" RTORRENT_SOCKET="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo "${RTORRENT_SCGI_SOCKET}" || echo "")" RTORRENT_SCGI_PROXY_TARGET_NETWORK="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo unix || echo tcp)" RTORRENT_SCGI_PROXY_TARGET_ADDRESS="$([[ "${RTORRENT_SCGI_BACKEND}" == "unix" ]] && echo "${RTORRENT_SCGI_SOCKET}" || echo "127.0.0.1:${RTORRENT_SCGI_PORT}")" RTORRENT_SCGI_PROXY_LISTEN="${RTORRENT_SCGI_PROXY_LISTEN}" RTORRENT_SCGI_PROXY_TOKEN="${RTORRENT_SCGI_PROXY_TOKEN}" RTORRENT_SCGI_PROXY_EXTRA_GROUPS="${RTORRENT_USER}" bash "${PROJECT_DIR}/scripts/install_pytorrent_only.sh" --yes --app-dir "${PYTORRENT_APP_DIR}" --port "${PYTORRENT_PORT}" --service-name "${PYTORRENT_SERVICE_NAME}" --profile-name "${PYTORRENT_PROFILE_NAME}" --scgi-url "${PYTORRENT_RTORRENT_SCGI_URL}"
|
||||
|
||||
CONFIGURE_ARGS=(
|
||||
--base-url "${PYTORRENT_BASE_URL}"
|
||||
--profile-name "${PYTORRENT_PROFILE_NAME}"
|
||||
--scgi-url "${PYTORRENT_RTORRENT_SCGI_URL}"
|
||||
)
|
||||
if [[ -n "${PYTORRENT_API_TOKEN}" ]]; then
|
||||
CONFIGURE_ARGS+=(--api-token "${PYTORRENT_API_TOKEN}")
|
||||
"${PYTORRENT_APP_DIR}/venv/bin/python" "${PYTORRENT_APP_DIR}/scripts/stack_installers/configure_pytorrent_api.py" --base-url "${PYTORRENT_BASE_URL}" --profile-name "${PYTORRENT_PROFILE_NAME}" --scgi-url "${PYTORRENT_RTORRENT_SCGI_URL}" --api-token "${PYTORRENT_API_TOKEN}"
|
||||
fi
|
||||
"${PYTORRENT_APP_DIR}/venv/bin/python" "${PYTORRENT_APP_DIR}/scripts/stack_installers/configure_pytorrent_api.py" "${CONFIGURE_ARGS[@]}"
|
||||
|
||||
echo "Done. pyTorrent: ${PYTORRENT_BASE_URL} | rTorrent SCGI: ${PYTORRENT_RTORRENT_SCGI_URL}"
|
||||
|
||||
Reference in New Issue
Block a user