socker backend support
This commit is contained in:
@@ -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}" \
|
||||
|
||||
Reference in New Issue
Block a user