# Running the server Installing termlessd on Linux as a system service, its settings, running it behind a proxy, the data folder, adding an account, upgrading, the doctor, and reading diagnostics, the trails, crash reports and undecoded frames. `termlessd` is one static binary (about 14 MB, musl, no dependencies) for `x86_64` and `aarch64` Linux. It needs a data folder it owns and a port to listen on; everything else is optional. This page installs it as a systemd service; to run it as a container instead, see [Running in Docker](/docs/docker). ## Install Releases come as one archive per processor: `termless--linux-x86_64.tar.gz` for most PCs and cloud servers, `termless--linux-aarch64.tar.gz` for ARM machines (Ampere and Graviton servers, a 64-bit Raspberry Pi). `uname -m` on the box tells you which (`arm64` is `aarch64`). Each archive holds one folder with the server, `install.sh`, `termlessd.service`, the Docker files and a README. On the box: ```sh tar xzf termless--linux-x86_64.tar.gz cd termless--linux-x86_64 sudo sh install.sh ``` The script creates the system user `termless`, installs the binary to `/usr/local/bin/termlessd`, installs and enables the hardened systemd unit (own user, `ProtectSystem=strict`, a 512 MB memory cap, no capabilities), and starts it with its data in `/var/lib/termless`, listening on `127.0.0.1:8780`. Running it again upgrades in place and restarts the service. ```sh sudo cat /var/lib/termless/setup-token # the one-time setup token, on a first run journalctl -u termlessd -n 50 # the log curl -s http://127.0.0.1:8780/api/v1/health # "version" is null without a key, so the version stays private ``` ### Reaching it The service listens on localhost only. Reach the dashboard over an SSH tunnel (`ssh -N -L 8780:127.0.0.1:8780 you@your-box`, then `http://127.0.0.1:8780`), or put it on your own domain with Caddy, nginx, a Cloudflare Tunnel or Tailscale ([Your own domain](/docs/domains)). Never open the port itself to the internet: API keys and the password would travel unencrypted, and a caller could pick its own address. The ways to reach it from elsewhere (a tunnel, a VPN, a proxy) and what each one costs: [Remote access](/docs/remote-access). ### Behind a reverse proxy Start with `--trust-proxy` (`TERMLESS_TRUST_PROXY=1`) so lockouts and the `Secure` cookie flag use the real client address and scheme. The server then reads the client IP from **one** header, `--proxy-header` / `TERMLESS_PROXY_HEADER` (default `X-Forwarded-For`, its last hop; `X-Real-IP` is never a fallback), and https from `X-Forwarded-Proto`. Two rules, both yours: the proxy must set or overwrite that header on every request it forwards, and nothing but the proxy may reach termlessd's port (keep `--listen 127.0.0.1:8780`). Otherwise a client picks its own address and the lockouts protect nothing. Without `--trust-proxy` every such header is ignored. ```text termless.example.com { reverse_proxy 127.0.0.1:8780 { header_up X-Forwarded-For {remote_host} } } ``` `header_up` replaces whatever the caller sent with the address Caddy sees, and Caddy sets `X-Forwarded-Proto` itself. To use `X-Real-IP` instead, write `header_up X-Real-IP {remote_host}` and start termlessd with `--proxy-header X-Real-IP`. nginx, a Cloudflare Tunnel and the checks that prove it works: [Your own domain](/docs/domains). ### First run With no admin password set, the server prints a one-time setup token to its log and writes it to `/setup-token` (`sudo cat /var/lib/termless/setup-token`). Open the dashboard; it asks for the token and a new password (15 to 200 characters with a lowercase letter, a capital, a digit and a symbol). Do this before you put the server on a domain: until then, whoever holds the token sets the password. Or set `TERMLESS_ADMIN_PASSWORD` in the service's environment before the first start to skip that step. `sudo sh install.sh --password` (or `termlessd passwd`) sets a new password later, from the box, and signs every dashboard session out. ## Settings Each setting is a flag or an environment variable; the flag wins. | Flag | Variable | Default | What | |---|---|---|---| | `--data DIR` | `TERMLESS_DATA` | `~/.local/share/termless` (`/var/lib/termless` under systemd) | The data folder. | | `--listen ADDR` | `TERMLESS_LISTEN` | `127.0.0.1:8780` | Address and port. | | `--trust-proxy` | `TERMLESS_TRUST_PROXY=1` | off | Take the client IP from the proxy header and https from `X-Forwarded-Proto`. Only behind a proxy you control that overwrites that header. | | `--proxy-header H` | `TERMLESS_PROXY_HEADER` | `X-Forwarded-For` | The one header carrying the client IP when `--trust-proxy` is on (last hop). `X-Real-IP` is never a fallback. | | `--trusted-proxies LIST` | `TERMLESS_TRUSTED_PROXIES` | `127.0.0.0/8,::1` | Where the proxy's connection comes from, as CIDRs. Forwarding headers from any other peer are ignored, even with `--trust-proxy`. Set it when the proxy runs on another machine or in a container. | | `--cookie-secure` | `TERMLESS_COOKIE_SECURE=1` | off (on when the request is https) | Always mark the session cookie `Secure`. | | `--web-dir DIR` | `TERMLESS_WEB` | built in | Serve the dashboard and docs from a folder instead of the embedded copy, for editing them. | | | `TERMLESS_LOG` | `info` | Log filter, for example `info,termless=debug`. | | | `TERMLESS_THREADS` | `2` | Async worker threads. Two carry 400,000 ticks a second to 200 clients at under 60 % of a core; raise it only for a measured reason (`docs/architecture.md` in the repository explains why more is slower). | | | `TERMLESS_REQUEST_TIMEOUT` | `30` | Seconds before a request (other than a stream) is given up with `504`. `0` removes the bound. | | | `TERMLESS_BROKER_TIMEOUT_MS` | `20000` | Milliseconds one call to the broker may take before it is `504 timeout` (1,000 to 120,000). A call that is never answered closes the broker link after three times this, so no late reply is taken for another call's. | | | `TERMLESS_TRADE_RESULT_TIMEOUT_MS` | `25000` | Milliseconds a trade waits for its final result once the broker took it (1,000 to 25,000, so the trade answers itself inside the 30 s request bound). Without one it is `504 unconfirmed`; a result that comes later, within 120 s, still settles its Idempotency-Key. | | | `TERMLESS_CATCH_UP_RETRY_S` | `60,120,300,600,900` | Seconds to wait before reading again the deals made during a gap when the broker's history did not answer the last read; the last value repeats. | | | `TERMLESS_TICK_HISTORY` | `1000` | Ticks kept per streaming symbol for `GET /ticks`, at most `100000`; `0` keeps none. An account keeps at most 100,000 over all its symbols together, whatever this says. | | | `TERMLESS_ADMIN_PASSWORD` | | Sets the admin password on the first start only. | | | `TERMLESS_ALLOW_PRIVATE_GATEWAYS=1` | off | Lets an account's gateway resolve to a loopback, link-local, private or carrier-grade NAT address. Refused with `400` otherwise. | | | `TERMLESS_ALLOW_INSECURE_GATEWAYS=1` | off | Lets an account use a plain `ws://` host (the fake broker used in tests); implies the private-gateways setting. Never in production. | | | `TERMLESS_TEST_PANIC_ROUTE=1` | off | Adds `GET /api/v1/test/panic`, which panics, so the tests can check what a panic is answered with (0.7.1). It writes a crash report like any panic. Never in production. | Commands: `termlessd serve` (the default), `termlessd passwd`, `termlessd doctor` (below), `termlessd crash-test --data /tmp/x` (panics on purpose to prove crash reports work on this box; give it a throwaway `--data`, since a report in the live data folder makes `/status` say `degraded` for 24 hours), `termlessd --version`. ## The doctor `termlessd doctor [--data DIR]` checks a box and prints one report with a verdict (`ok`, `warnings` or `problems`; exit code 0, 1 or 2). It works offline, before or beside a running server, and `GET /api/v1/diagnostics/doctor` (admin) runs the same checks against the live server and returns them as JSON. ```sh termlessd doctor --data /var/lib/termless ``` ```text termlessd 0.1.0 doctor: warnings data folder: /var/lib/termless ok data folder /var/lib/termless exists and is writable ok master.key /var/lib/termless/master.key present (owner-only) ok database /var/lib/termless/termless.db (132 KB) integrity ok; rows: accounts 1, keys 2, audit 4821, account_events 310, equity_samples 1440 ok listen serving on http://127.0.0.1:8780 ok gateway pepperstone-12345678: mt5-demo01.pepperstone.com:443 is Pepperstone Group Limited build 6090 (2 servers); connected, build 6090 WARN clock 7 s off the broker's clock fix: enable NTP (timedatectl set-ntp true); candle times and expirations depend on it ok disk 18240 MB free; termless uses 3 MB ``` | Check | What it looks at | |---|---| | `data folder` | Exists, is writable, is owner-only (mode `0700`). | | `master.key`, `setup-token` | Present and owner-only; the token only until setup is done. | | `database` | Opens, passes `PRAGMA integrity_check`, with row counts per table. A running server holds the lock; the doctor says so rather than failing. | | `listen` | The address is serving, free, or cannot be bound. | | `gateway` (one per account) | DNS, then TLS and the web terminal page with its build (or a TCP connect for a plain `ws://` test gateway), plus the session's live state when the server is running. | | `clock` | The box against the first connected broker; warns past 5 s, because candle times and expirations depend on it. | | `disk` | Free space and what termless uses; fails under 200 MB, warns under 1 GB. | Every `warn` and `fail` carries a `fix`: what to do, in one line. Startup errors do the same: a port in use, an unwritable data folder and a damaged `master.key` each name the fix. ## The data folder Created with mode `0700`; every file inside is owner-only. | Path | What | Back up? | |---|---|---| | `termless.db` | SQLite: settings, accounts (passwords sealed with AES-256-GCM), keys (hashes only), sessions, the server directory, the trails (audit, connection events, equity samples, idempotency results), the magic numbers and long comments kept for orders, and each account's newest 1,024 trade events (so their numbering carries on across a restart). | Yes. | | `master.key` | The key that seals account passwords. Losing it makes every stored MT5 password unreadable: you would add the accounts again. | Yes, separately from the database. | | `setup-token` | The one-time token, present until setup is done. | No. | | `termlessd.pid` | Written at start, removed at a clean exit. Present at start = the last run ended uncleanly, and a report is written. | No. | | `termlessd.lock` | Held locked while termlessd runs (0.6.3): a second termlessd started on the same folder is refused before it touches anything, with a message naming the folder and the live pid. | No. | | `logs/termlessd..log` | One log file per day, 14 kept. | As you like. | | `crashes/` | Crash reports, one text file per panic or unclean exit. | For a bug report. | | `captures/undecoded.jsonl` | Frames from the broker the client could not decode (below). | For a bug report. | ## Adding an account In the dashboard, **Accounts > Add account**: pick the server, enter the login and password, choose the symbols to keep streaming. The directory has 57 servers built in, from these brokers: MetaQuotes (demo), Pepperstone, Fusion Markets, IC Markets, Exness (and its Expert Execution servers), Admirals, BlackBull Markets, Deriv, Key to Markets, Fxview, Errante, Axi, Octa, OANDA, FBS (Tradestone), PU Prime, Headway and Taurex; prop firms: FTMO, The5ers, E8 Markets, FundingPips, FundedNext, Maven, Audacity, Funded Trading Plus, AquaFunded, FXIFY, BrightFunded, OANDA Prop Trader and For Traders. Search it by broker, server name or host; spaces, dashes and dots don't matter. For any other broker, **Check a host** with its web terminal's host reads that page and adds its servers ([Find your server](/docs/find-your-server) shows where to find the server name and that address). Or over the API: ```sh curl -s -X POST "$TERMLESS_URL/api/v1/accounts" -b cookies.txt -H "Content-Type: application/json" \ -d '{"label": "Pepperstone demo", "login": 12345678, "password": "your MT5 password", "server": "Pepperstone-Demo", "symbols": ["XAUUSD", "EURUSD"]}' ``` The account connects in the background; poll `GET /api/v1/accounts/{id}` until `status.connected` is true. A refused login shows as `status.login_rejected: true` with `last_error`, and the account then retries only every five minutes so a wrong password cannot get it locked at the broker. Fix it with `PATCH /api/v1/accounts/{id}` and a new `password`. A login refused within a minute of losing a working connection is different: brokers refuse logins for a few seconds while their server restarts (often at weekends), so that one is tried again after 10, 20, 30 and 60 seconds before the five-minute wait. Brokers must have web access turned on for the server (the same thing that lets their web terminal work). The host you connect to decides which trade servers you can reach; `POST /api/v1/servers/check` with a host reports its company, build and servers. Gateways must be on the public internet: a host that resolves to a loopback, link-local, private or carrier-grade NAT address is refused with `400` (by the check and when adding or changing an account) unless the server runs with `TERMLESS_ALLOW_PRIVATE_GATEWAYS=1`. A failed check answers one generic `502`; the reason is in the log and in the audit trail (`kind: "server_check"`). ### Brokers with broken certificates Termless always checks a broker's certificate, the way a browser does, and never turns that check off. Some brokers set theirs up badly; three cases are handled: - **The broker leaves out a certificate in the middle** (IC Markets does). Browsers fetch the missing one from the address written in the broker's certificate; Termless does the same (only from a public address, at most 16 KB, then the whole chain must still lead to a trusted authority), keeps it in memory, and ships the one IC Markets needs in case the fetch is blocked. Nothing to do; the log says once that the broker's chain is incomplete. - **The address is a bare IP** (Exness's servers). Add the name on its certificate as `tls_name` (the directory already knows Exness's: `exwebterm.com`); Termless connects to the IP and checks the certificate for that name. - **The certificate is for another name, or from a private authority** (Alpari, `mt5.deriv.com`, Blueberry Funded). **Check a host** answers `untrusted_certificate` and shows the certificate: its names, who issued it, when it expires, and its key fingerprint (`spki_sha256`). If you are sure it is the broker's real address, pin that key: check again with `fingerprint` set to it (or `POST /api/v1/servers/{server}/trust`). From then on that host is accepted with that key only, and refused with `certificate_changed` if the key ever changes; `DELETE` the trust to undo it. Pins and unpins are in the audit trail. A broker whose web terminal only lets browsers in (a Cloudflare challenge, as FxPro and AvaTrade do) answers `browser_only`: Termless cannot reach it, and pinning does not change that. ## Upgrading Your accounts, keys, settings and history live in `/var/lib/termless`, never in the release folder, so an upgrade only swaps the program. Unpack the new release anywhere and run its installer: ```sh tar xzf termless--linux-x86_64.tar.gz cd termless--linux-x86_64 sudo sh install.sh ``` ```text upgrading: termlessd 0.1.0 (x86_64-unknown-linux-musl) -> termlessd 0.2.0 (x86_64-unknown-linux-musl) data backed up to /var/lib/termless/backups/20261007-174512 running: termlessd 0.2.0 (x86_64-unknown-linux-musl) ``` Step by step, the installer: 1. stops the service, so nothing writes to the data while it is copied; 2. copies `termless.db` and `master.key` to `/var/lib/termless/backups/