Skip to content

Add a configuration-file path argument to the tracker executable #2151

Closed

Description

@josecelano

Goal

Allow operators to start torrust-tracker with an explicit configuration-file path, for example torrust-tracker --config-toml-path /etc/torrust/tracker/tracker.toml, without relying on a process environment variable.

Background

The tracker executable currently obtains its configuration through TORRUST_TRACKER_CONFIG_TOML, TORRUST_TRACKER_CONFIG_TOML_PATH, or the default development file. An explicit argument makes configuration selection visible at the executable boundary and allows native child-process tests to use isolated configuration without environment-source injection.

This is independent of closed EPIC #1978. That EPIC changed the configuration schema; this issue changes executable bootstrap source selection.

Required precedence

Base sources are mutually exclusive; only the winning source is used and the others are not merged. Per-value overrides are then merged on top of the selected base source.

  1. TORRUST_TRACKER_CONFIG_OVERRIDE_<PATH> per-value overrides
  2. --config-toml-path <PATH> / -c <PATH>
  3. TORRUST_TRACKER_CONFIG_TOML complete TOML content
  4. TORRUST_TRACKER_CONFIG_TOML_PATH TOML file
  5. Bootstrap default development file
  6. Rust schema defaults for non-mandatory values

Without the argument, the current behavior remains: complete TOML content beats an environment-selected file, which beats the default file. Overrides must continue to win over a CLI-selected file.

Scope

  • Add -c / --config-toml-path <PATH> to the main executable using the existing clap dependency, without clap's env attribute.
  • Pass typed source selection through binary, application, bootstrap, and configuration layers without mutating process environment variables.
  • Resolve a CLI path exactly from the current working directory; do not search parent directories.
  • Treat an absent or empty argument value as a descriptive usage error with exit code 2.
  • Treat missing, unreadable, non-file, or invalid-TOML CLI sources as descriptive startup errors with exit code 1 and no listener started.
  • Retain current TORRUST_TRACKER_CONFIG_TOML_PATH missing-file and parent-directory-search behavior for compatibility; document the intentional distinction.
  • Add configuration, executable-boundary, and manual verification coverage, including two concurrent child processes with isolated CLI paths, storage, and port-zero bindings.

Acceptance criteria

  • torrust-tracker accepts -c and --config-toml-path <PATH>.
  • All eight combinations of CLI path, complete TOML environment source, and environment path select the required base source.
  • Overrides replace matching values for every selected base source.
  • Existing environment-only behavior is unchanged.
  • Invalid CLI input returns the specified descriptive error and exit code, without starting listeners.
  • Relative CLI paths cannot load a same-named file from a parent directory.
  • Relevant tests and linter all pass; manual precedence, override, invalid-source, and parallel-child scenarios are recorded.

Design constraints

  • Keep CLI parsing separate from the configuration package; no environment reads in the parser.
  • Preserve app::start() as the compatibility wrapper for current callers and add a parameterized entry point as needed.
  • Preserve secret redaction; do not log TOML contents or secrets.
  • Follow docs/adrs/20260519000000_define_global_cli_output_contract.md for output channels and exit codes as far as this work touches them. Full migration of existing output behavior remains separate work.

Specification

The reviewed implementation plan, ownership/lifetime invariants, risks, acceptance verification table, and mandatory manual scenarios are tracked in docs/issues/open/<issue-number>-add-tracker-config-path-argument/ISSUE.md after the issue number is assigned.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions