mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-03-28 17:42:45 +01:00
Major refactor of meshcore-bridge to maintain a single long-lived meshcli
process instead of spawning new processes per request.
Changes:
- Add MeshCLISession class managing persistent subprocess.Popen session
- Implement thread-safe command queue with event-based synchronization
- Add stdout/stderr reader threads with JSON advert detection
- Log adverts automatically to {device_name}.adverts.jsonl with timestamp
- Add end-of-response markers (echo "___END_{cmd_id}___") for multiplexing
- Implement watchdog thread for auto-restart on meshcli crash
- Update /cli endpoint to delegate commands through persistent session
- Add MC_CONFIG_DIR and MC_DEVICE_NAME env vars to docker-compose.yml
Architecture benefits:
- No more USB port conflicts between concurrent requests
- Continuous advert logging without breaking /cli compatibility
- Better error recovery with automatic session restart
- Reduced overhead from process spawning
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
67 lines
2.0 KiB
YAML
67 lines
2.0 KiB
YAML
services:
|
|
# MeshCore Bridge - Handles USB communication with meshcli
|
|
meshcore-bridge:
|
|
build:
|
|
context: ./meshcore-bridge
|
|
dockerfile: Dockerfile
|
|
container_name: meshcore-bridge
|
|
restart: unless-stopped
|
|
devices:
|
|
- "${MC_SERIAL_PORT}:${MC_SERIAL_PORT}"
|
|
volumes:
|
|
- "${MC_CONFIG_DIR}:/root/.config/meshcore:rw"
|
|
environment:
|
|
- MC_SERIAL_PORT=${MC_SERIAL_PORT}
|
|
- MC_CONFIG_DIR=/root/.config/meshcore
|
|
- MC_DEVICE_NAME=${MC_DEVICE_NAME}
|
|
networks:
|
|
- meshcore-net
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:5001/health')"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 10s
|
|
|
|
# Main Web UI - Communicates with bridge via HTTP
|
|
mc-webui:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
container_name: mc-webui
|
|
restart: unless-stopped
|
|
ports:
|
|
- "${FLASK_PORT:-5000}:5000"
|
|
volumes:
|
|
- "${MC_CONFIG_DIR}:/root/.config/meshcore:rw"
|
|
- "${MC_ARCHIVE_DIR:-./archive}:/root/.archive/meshcore:rw"
|
|
environment:
|
|
- MC_BRIDGE_URL=http://meshcore-bridge:5001/cli
|
|
- MC_DEVICE_NAME=${MC_DEVICE_NAME}
|
|
- MC_CONFIG_DIR=/root/.config/meshcore
|
|
- MC_REFRESH_INTERVAL=${MC_REFRESH_INTERVAL:-60}
|
|
- MC_INACTIVE_HOURS=${MC_INACTIVE_HOURS:-48}
|
|
- MC_ARCHIVE_DIR=/root/.archive/meshcore
|
|
- MC_ARCHIVE_ENABLED=${MC_ARCHIVE_ENABLED:-true}
|
|
- MC_ARCHIVE_RETENTION_DAYS=${MC_ARCHIVE_RETENTION_DAYS:-7}
|
|
- FLASK_HOST=${FLASK_HOST:-0.0.0.0}
|
|
- FLASK_PORT=${FLASK_PORT:-5000}
|
|
- FLASK_DEBUG=${FLASK_DEBUG:-false}
|
|
env_file:
|
|
- .env
|
|
depends_on:
|
|
meshcore-bridge:
|
|
condition: service_healthy
|
|
networks:
|
|
- meshcore-net
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:5000/api/status')"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 10s
|
|
|
|
networks:
|
|
meshcore-net:
|
|
driver: bridge
|