Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f122f47aa | |||
| 14de77926f | |||
| 3cbf36e0ad | |||
| 8204d8d41e | |||
| a95db23240 | |||
| 005817d499 | |||
| 7a80057cb5 | |||
| 214ee8dd90 | |||
| 38043d7d1f | |||
| 7af9789db7 | |||
| 9f341a5b14 | |||
| 3391523d45 | |||
| 23d469d008 | |||
| a3fa38b740 | |||
| c996ade142 | |||
| 2a2c29de29 | |||
| 22a3078af9 |
@@ -3,6 +3,7 @@ __pycache__
|
|||||||
*.pyc
|
*.pyc
|
||||||
*.pyo
|
*.pyo
|
||||||
config.json
|
config.json
|
||||||
|
data/
|
||||||
screenshots/
|
screenshots/
|
||||||
.claude/
|
.claude/
|
||||||
CLAUDE.md
|
CLAUDE.md
|
||||||
|
|||||||
@@ -26,3 +26,6 @@ Thumbs.db
|
|||||||
# Local config — contains the admin password hash and session secret.
|
# Local config — contains the admin password hash and session secret.
|
||||||
# Fresh installs start from config.json.example (see CONFIG.md).
|
# Fresh installs start from config.json.example (see CONFIG.md).
|
||||||
config.json
|
config.json
|
||||||
|
|
||||||
|
# Docker config volume (holds the live config.json with secrets)
|
||||||
|
data/
|
||||||
|
|||||||
@@ -18,6 +18,14 @@ python3 server.py
|
|||||||
|
|
||||||
Access at http://localhost:{web_port} (configured in config.json)
|
Access at http://localhost:{web_port} (configured in config.json)
|
||||||
|
|
||||||
|
### Deployment / fielding notes
|
||||||
|
|
||||||
|
- **Config path** is overridable via the `ADSBIT_CONFIG` env var (defaults to `config.json` beside `server.py`). Docker uses `/app/data/config.json` on a mounted volume.
|
||||||
|
- **`/health`** (no auth) returns status/version/receiver/flight counts — used by the Docker `HEALTHCHECK` and any external monitoring.
|
||||||
|
- **`VERSION`** constant in `server.py` is the single source of truth; surfaced at startup, via `GET /api/config`, and in the admin header. Bump it for releases.
|
||||||
|
- **Auto-scan** (`scan_for_receivers`) skips subnets larger than `MIN_SCAN_PREFIX` (/20) so a docker `/16` doesn't stall startup; the manual scan endpoint enforces the same limit.
|
||||||
|
- **`docker-entrypoint.sh`** seeds `config.json` from `config.json.example` on first run, so a fresh `docker compose up` needs no manual steps. SIGTERM/SIGINT shut down cleanly (no traceback).
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
### Components
|
### Components
|
||||||
|
|||||||
+9
-2
@@ -13,9 +13,16 @@ RUN pip install --no-cache-dir -r requirements.txt && \
|
|||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
RUN chmod +x /app/docker-entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 2001
|
EXPOSE 2001
|
||||||
|
|
||||||
ENV PYTHONUNBUFFERED=1
|
# Persist config on a mounted volume by default (see docker-compose.yml).
|
||||||
|
ENV PYTHONUNBUFFERED=1 \
|
||||||
|
ADSBIT_CONFIG=/app/data/config.json
|
||||||
|
|
||||||
CMD ["python3", "server.py"]
|
# Liveness probe against the unauthenticated /health endpoint.
|
||||||
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
|
||||||
|
CMD python3 -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:2001/health',timeout=4).status==200 else 1)" || exit 1
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
||||||
|
|||||||
@@ -44,14 +44,16 @@ On first run, visit http://localhost:2001 and the setup wizard will guide you th
|
|||||||
### First Run
|
### First Run
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Create a config file (the setup wizard runs if you skip this)
|
# Build and start — no config step needed
|
||||||
cp config.json.example config.json
|
|
||||||
|
|
||||||
# Build and start
|
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
The web UI is available at http://localhost:2001.
|
A config file is created automatically in `data/` on first run, then the
|
||||||
|
browser **setup wizard** walks you through receiver, location, and password
|
||||||
|
setup. The web UI is available at http://localhost:2001.
|
||||||
|
|
||||||
|
A `/health` endpoint (used by the container healthcheck) reports status,
|
||||||
|
version, and receiver/flight counts: `curl http://localhost:2001/health`.
|
||||||
|
|
||||||
### Useful Commands
|
### Useful Commands
|
||||||
|
|
||||||
@@ -82,11 +84,11 @@ The following paths are bind-mounted from the repo directory and persist across
|
|||||||
|
|
||||||
| Path | Contents |
|
| Path | Contents |
|
||||||
|------|----------|
|
|------|----------|
|
||||||
| `config.json` | Server configuration and credentials |
|
| `data/` | Server configuration and credentials (`config.json`, auto-seeded) |
|
||||||
| `images/` | Aircraft and UI sprites (including uploads) |
|
| `images/` | Aircraft and UI sprites (including uploads) |
|
||||||
| `backgrounds/` | Theme background images (including custom themes) |
|
| `backgrounds/` | Theme background images (including custom themes) |
|
||||||
|
|
||||||
Host networking (`network_mode: host`) is used so the server can auto-scan your LAN for ADS-B receivers.
|
Host networking (`network_mode: host`) is used so the server can auto-scan your LAN for ADS-B receivers. Auto-scan skips oversized subnets (larger than /20, e.g. a Docker bridge `172.17.0.0/16`); if your receiver lives on such a network, set it explicitly via the admin Receivers tab.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
@@ -104,8 +106,8 @@ ADS-Bit uses a first-run setup wizard to configure your installation. You can al
|
|||||||
"receiver_port": 30003,
|
"receiver_port": 30003,
|
||||||
"location": {
|
"location": {
|
||||||
"name": "My Location",
|
"name": "My Location",
|
||||||
"lat": 36.2788,
|
"lat": 0.0,
|
||||||
"lon": -115.2283
|
"lon": 0.0
|
||||||
},
|
},
|
||||||
"web_port": 2001,
|
"web_port": 2001,
|
||||||
"theme": "desert"
|
"theme": "desert"
|
||||||
|
|||||||
+4
-2
@@ -6,9 +6,11 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
- PYTHONUNBUFFERED=1
|
- PYTHONUNBUFFERED=1
|
||||||
|
- ADSBIT_CONFIG=/app/data/config.json
|
||||||
volumes:
|
volumes:
|
||||||
# Persist config (copy config.json.example to config.json before first run)
|
# Config persists here; auto-seeded from config.json.example on first run
|
||||||
- ./config.json:/app/config.json
|
# (a directory mount, so a fresh `docker compose up` just works).
|
||||||
|
- ./data:/app/data
|
||||||
# Persist custom sprite uploads
|
# Persist custom sprite uploads
|
||||||
- ./images:/app/images
|
- ./images:/app/images
|
||||||
# Persist custom theme backgrounds
|
# Persist custom theme backgrounds
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Seed a config file on first run so `docker compose up` works on a fresh
|
||||||
|
# clone with no manual steps. The config lives on a mounted data volume so it
|
||||||
|
# persists across container rebuilds.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
: "${ADSBIT_CONFIG:=/app/config.json}"
|
||||||
|
CONFIG_DIR=$(dirname "$ADSBIT_CONFIG")
|
||||||
|
mkdir -p "$CONFIG_DIR"
|
||||||
|
|
||||||
|
if [ ! -f "$ADSBIT_CONFIG" ]; then
|
||||||
|
echo "[entrypoint] No config at $ADSBIT_CONFIG — seeding from config.json.example"
|
||||||
|
cp /app/config.json.example "$ADSBIT_CONFIG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec python3 server.py
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 264 KiB |
@@ -17,10 +17,16 @@ from aiohttp import web, ClientSession, ClientTimeout
|
|||||||
import netifaces
|
import netifaces
|
||||||
import bcrypt
|
import bcrypt
|
||||||
|
|
||||||
VERSION = "1.1.0"
|
VERSION = "1.1.1"
|
||||||
|
|
||||||
WEB_DIR = Path(__file__).parent
|
WEB_DIR = Path(__file__).parent
|
||||||
CONFIG_FILE = WEB_DIR / "config.json"
|
# Config path is overridable (handy for containers persisting config on a
|
||||||
|
# named volume); defaults to config.json next to this script for bare-metal.
|
||||||
|
CONFIG_FILE = Path(os.environ.get("ADSBIT_CONFIG") or (WEB_DIR / "config.json"))
|
||||||
|
|
||||||
|
# Smallest subnet prefix (largest network) we'll auto-scan: /20 = 4094 hosts.
|
||||||
|
# Anything bigger (e.g. a docker /16) is skipped to keep scans fast and safe.
|
||||||
|
MIN_SCAN_PREFIX = 20
|
||||||
|
|
||||||
# Track server start time
|
# Track server start time
|
||||||
SERVER_START_TIME = time.time()
|
SERVER_START_TIME = time.time()
|
||||||
@@ -414,6 +420,15 @@ async def scan_for_receivers():
|
|||||||
if ip and netmask and not ip.startswith('127.'):
|
if ip and netmask and not ip.startswith('127.'):
|
||||||
try:
|
try:
|
||||||
network = ipaddress.IPv4Network(f"{ip}/{netmask}", strict=False)
|
network = ipaddress.IPv4Network(f"{ip}/{netmask}", strict=False)
|
||||||
|
# Skip subnets too large to scan quickly (e.g. a docker
|
||||||
|
# bridge /16 = 65k hosts). Without this, AUTO discovery
|
||||||
|
# hammers the network and stalls startup on any host with
|
||||||
|
# Docker or a large/16. Use MANUAL or a custom subnet for
|
||||||
|
# receivers that live on such networks.
|
||||||
|
if network.prefixlen < MIN_SCAN_PREFIX:
|
||||||
|
print(f"Skipping {network} on {iface}: too large "
|
||||||
|
f"({network.num_addresses} hosts) for auto-scan")
|
||||||
|
continue
|
||||||
found.extend(await _scan_subnet(network, port))
|
found.extend(await _scan_subnet(network, port))
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(f"Invalid network {ip}/{netmask}: {e}")
|
print(f"Invalid network {ip}/{netmask}: {e}")
|
||||||
@@ -984,9 +999,10 @@ async def handle_admin_scan_receivers(request):
|
|||||||
return web.json_response(
|
return web.json_response(
|
||||||
{"error": f"Invalid subnet: {subnet}"}, status=400)
|
{"error": f"Invalid subnet: {subnet}"}, status=400)
|
||||||
|
|
||||||
if network.prefixlen < 20:
|
if network.prefixlen < MIN_SCAN_PREFIX:
|
||||||
return web.json_response(
|
return web.json_response(
|
||||||
{"error": "Subnet too large (max /20 = 4096 hosts)"}, status=400)
|
{"error": f"Subnet too large (max /{MIN_SCAN_PREFIX} = "
|
||||||
|
f"{2 ** (32 - MIN_SCAN_PREFIX) - 2} hosts)"}, status=400)
|
||||||
|
|
||||||
port = config['receiver_port']
|
port = config['receiver_port']
|
||||||
found = await _scan_subnet(network, port)
|
found = await _scan_subnet(network, port)
|
||||||
@@ -1172,6 +1188,17 @@ async def handle_http(request):
|
|||||||
return web.Response(status=404, text="Not Found")
|
return web.Response(status=404, text="Not Found")
|
||||||
|
|
||||||
|
|
||||||
|
async def handle_health(request):
|
||||||
|
"""GET /health - liveness/readiness probe (no auth, no secrets)."""
|
||||||
|
return web.json_response({
|
||||||
|
"status": "ok",
|
||||||
|
"version": VERSION,
|
||||||
|
"receivers": len(receivers),
|
||||||
|
"flights": len(flights),
|
||||||
|
"uptime_seconds": int(time.time() - SERVER_START_TIME),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Application setup
|
# Application setup
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -1184,6 +1211,7 @@ async def start_http_server():
|
|||||||
app.router.add_get('/ws', websocket_handler)
|
app.router.add_get('/ws', websocket_handler)
|
||||||
|
|
||||||
# Public API
|
# Public API
|
||||||
|
app.router.add_get('/health', handle_health)
|
||||||
app.router.add_get('/api/receiver-location', handle_receiver_location)
|
app.router.add_get('/api/receiver-location', handle_receiver_location)
|
||||||
app.router.add_get('/api/config', handle_config)
|
app.router.add_get('/api/config', handle_config)
|
||||||
|
|
||||||
@@ -1282,4 +1310,11 @@ async def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# Make SIGTERM (docker stop, systemctl stop) raise KeyboardInterrupt like
|
||||||
|
# SIGINT does, so shutdown is clean and quiet instead of a stack trace.
|
||||||
|
import signal
|
||||||
|
signal.signal(signal.SIGTERM, signal.default_int_handler)
|
||||||
|
try:
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
except (KeyboardInterrupt, SystemExit):
|
||||||
|
print("ADS-Bit server shutting down.")
|
||||||
|
|||||||
Reference in New Issue
Block a user