11 KiB
Debian 13 deployment baseline and bandwidth assessment
Assessment date: 23 October 2026.
Intended environment
The operator specified Debian 13, an application under /home/<download_user>/, and write access to /mnt/media/WIP/ through the plex group, with sudo available for administration. A concrete project directory such as /home/<download_user>/Proxer-Downloader/ can be used without hardcoding the account name in application code.
These are operator-supplied deployment requirements. This checkout has not inspected or changed that server, its users, PM2 state, mount permissions, MongoDB, firewall, or network interfaces.
Application identity and paths
Run the web application, PM2 daemon, Node workers, and Python download children as the download account. Access to the media directory should work through ordinary group permissions or the existing ACL. Administrative sudo access does not require the application itself to execute as root.
Use the project's configuration for the actual locations:
| Setting | Intended value or requirement |
|---|---|
| Project working directory | /home/<download_user>/Proxer-Downloader/, or the chosen directory under that home |
OUTPUT_DIR |
/mnt/media/WIP |
VENV_PYTHON |
Absolute path to this project's virtual environment Python executable |
MONGO_URI |
Existing deployment connection string, kept outside version control |
MONGO_DB |
downloads unless deliberately configured otherwise; web and workers must agree |
TOKEN_PREFIX |
Configured cookie name followed by =; do not put a live cookie token in documentation |
MAX_SERIES_EPISODES |
Bounded per-submission range; Phase 1 default is 500 |
PYTHONDONTWRITEBYTECODE |
1, in addition to the worker's -B launch argument |
The current lockfile's MongoDB driver requires Node >=20.19.0; verify the installed runtime against package-lock.json. Preserve the existing Python streaming dependency versions during this phase, using an isolated virtual environment. Dependency upgrades require separate stream compatibility verification.
PM2 supports a systemd startup entry for a chosen user and home directory, and restores the saved process list on boot. Generate that startup integration as the intended download account and review the exact command produced for that installation. Avoid accidentally operating a second root-owned PM2 daemon. See the PM2 startup documentation.
Media access check before deployment
Confirm the running process identity, not only the interactive login, has the expected plex membership. Inspect the mount, directory traversal permissions, ACL, and available space before starting workers. If group membership was changed, restart the relevant service/session so its group list is refreshed. Existing shared media permissions should be preserved; the rollout does not call for recursively changing ownership or permissions under /mnt/media.
For a systemd-managed process, User=, SupplementaryGroups=, WorkingDirectory=, and UMask= provide explicit execution settings. A group-compatible output mask should be chosen to match the existing media policy. The actual mount's ACL may also affect resulting permissions. See Debian's systemd.exec manual.
A single small create/write/remove probe by the download account can validate the intended output directory at deployment time. It has not been performed by this source-only Phase 1 work. No routine runtime command needs sudo merely to write an MP4 when the directory permissions are correct.
Bandwidth decision
Phase 1 conclusion: Debian 13 provides suitable external mechanisms, but no bandwidth backend is enabled or performance-validated by this change. The later worker-controls phase must demonstrate global and per-worker incoming limits on the intended host before reporting a cap as enforced.
The protected download_mp4 implementation supplies no limiter callback and does not support byte-level resume. Preserve that transport and place enforcement outside the Python library. Delay between episodes, worker count, CPU quota, disk I/O quota, or speed measurement are different controls and must not be presented as a byte-rate cap.
Recommended design: isolated worker traffic with an external shaper
Use a dedicated, identifiable path for Python download traffic. A worker network namespace or equivalent isolated interface is a candidate that can coexist with native PM2: the Node worker may remain under PM2 while the supervised download child enters its registered worker network context. Filesystem access and the download account remain unchanged. Debian's ip-netns manual documents executing namespace-unaware programs in a named network namespace. This is a proposed architecture, not a configuration already installed here.
A production prototype should route all participating download traffic through a common worker-bound shaping point, with one parent bandwidth budget and a class for each registered worker. A dedicated gateway interface or an IFB-based path is a possible implementation; select the exact topology after inspecting existing routes, interfaces, DNS, IPv4/IPv6, firewall policy, and local services. Classification must remain valid after address translation and must cover return traffic. Classifying an incoming download solely by the Python process ID is insufficient as a design specification.
Linux tc shapes traffic on an interface's outgoing path; inbound policing has different behavior. To control downloads, place the shaper on the outgoing side of a path leading toward the workers, or use a deliberately tested redirection mechanism. A limit attached only to the physical NIC's outbound traffic does not establish a download cap. See Debian's tc manual.
HTB is a candidate for a shared parent and per-worker children. Its rate, ceil, classification, and burst settings must be configured together and verified; the parent must cover all worker classes. This gives the required semantics that four workers capped at 3 MiB/s still share an 8 MiB/s global ceiling. Account for protocol overhead and the defined measurement interval when setting tolerances. See Debian's tc-htb manual.
Start with one active download per worker. Keep bandwidth policy distinct from how many workers may run. A later change to multi-child workers must keep their aggregate traffic within the worker's class.
Privilege separation
Network setup and shaping require administrative network permissions; ordinary media-directory group access does not provide them. Linux describes interface, routing, firewall, and related privileges under CAP_NET_ADMIN. See Debian's capabilities manual.
The application should request a narrowly defined operation from a separately installed, administrator-controlled helper or service. The helper must resolve registered worker IDs and allowlisted rates/interfaces itself. It must not accept arbitrary shell commands, device names, scripts, or namespace paths from HTTP requests. Download children should run under the download account after entering their prepared context. Do not grant the web application unrestricted passwordless sudo, and do not run the web server as root to obtain traffic control.
Debian systemd can join a prepared namespace using NetworkNamespacePath= for suitable services. Its network accounting and address filtering settings are useful for observation and policy, but are not a general download-bytes-per-second limiter. See the systemd execution manual and resource-control manual. The exact PM2/helper/service integration remains a later implementation choice.
Lower-infrastructure candidate: trickle and trickled
Debian 13 includes trickle. It is a cooperative userspace shaper for supported stream sockets; its manual excludes statically linked and setuid executables. A compatible dynamically linked Python process is therefore worth testing, but the installed Python/OpenSSL/Requests stack must be measured rather than assumed compatible. The wrapper's use of library interposition also deserves explicit review against the requirement to preserve stream behavior. See the Debian package page and trickle manual.
trickled coordinates several participating sessions and documents an aggregate download limit. Independent standalone trickle processes cannot establish one shared global budget by themselves. Use a private, explicitly configured coordination socket if this candidate is tested, and verify both the local worker ceiling and the shared limit under failure and restart. See the trickled manual.
This remains a candidate, not a shipped fallback. The application must not silently run an advertised limited worker without enforcement if its limiter is missing or unhealthy. Per-job caps and dynamic cap changes should only be exposed after the selected backend's behavior is proven.
Required host facts and controlled validation
Before implementing the limiter, establish the actual PM2 service identity and installation, Python executable, kernel/network capability availability, interface/route topology, IPv6 usage, firewall manager, and whether other applications share the proposed network path. Confirm that MongoDB and the web management interface remain reachable according to their existing access model. No assumption that sudo membership automatically grants a particular noninteractive helper permission should be baked into code.
Use a controlled local or staging HTTP/HTTPS server with generated payloads for the initial benchmark. Test the unchanged protected download function with bytecode writes disabled; no user token or production media source is necessary for that test.
Acceptance cases for the later implementation:
- One transfer respects its cap over a specified measurement interval, including a defined short burst allowance.
- Two and four simultaneous workers respect both their individual ceilings and the aggregate parent budget.
- Idle workers release unused capacity according to the chosen sharing policy.
- IPv4 and IPv6 follow the enforced path, and redirects do not escape it.
- Resolver requests, TLS, long transfers, missing content lengths, and slow servers remain functional.
- Limiter loss or misconfiguration produces a visible enforcement failure; it does not silently become unlimited.
- Reducing or removing a cap has a documented immediate/next-job/restart behavior.
- Worker stop, cancellation, and reboot leave no orphan download processes or abandoned network rules.
- Unrelated host traffic remains outside the downloader-specific policy.
- All protected-library hashes and entries still match the baseline after the run.
No privileged helper, tc rule, namespace, systemd unit, sudoers rule, or bandwidth setting is created by Phase 1. This document supplies the deployment boundary and feasibility decision for the later worker-controls phase.