feat: Add server management and database migrations

- Add start/stop/restart/status commands to Makefile
- Add health endpoint with uptime tracking
- Add CLI module (esp32-web command)
- Add initial database migration
- Listen on all interfaces (0.0.0.0:5500)

Bump version to 0.1.1
This commit is contained in:
user
2026-02-05 21:03:35 +01:00
parent a676136f5d
commit a8f616970a
9 changed files with 550 additions and 8 deletions

View File

@@ -1,13 +1,56 @@
.PHONY: build run dev stop logs test migrate clean install
.PHONY: build run dev stop logs test migrate clean install start restart status
APP_NAME := esp32-web
PORT := 5500
HOST := 0.0.0.0
PIDFILE := /tmp/esp32-web.pid
LOGFILE := /tmp/esp32-web.log
install:
pip install -e ".[dev]"
# Server management
start:
@if [ -f $(PIDFILE) ] && kill -0 $$(cat $(PIDFILE)) 2>/dev/null; then \
echo "Server already running (PID $$(cat $(PIDFILE)))"; \
else \
echo "Starting server on $(HOST):$(PORT)..."; \
nohup flask --app src/esp32_web run --host $(HOST) --port $(PORT) > $(LOGFILE) 2>&1 & \
echo $$! > $(PIDFILE); \
sleep 1; \
echo "Server started (PID $$(cat $(PIDFILE)))"; \
fi
stop:
@if [ -f $(PIDFILE) ]; then \
echo "Stopping server (PID $$(cat $(PIDFILE)))..."; \
kill $$(cat $(PIDFILE)) 2>/dev/null || true; \
rm -f $(PIDFILE); \
echo "Server stopped"; \
else \
echo "Server not running"; \
fi
restart: stop
@sleep 1
@$(MAKE) start
status:
@if [ -f $(PIDFILE) ] && kill -0 $$(cat $(PIDFILE)) 2>/dev/null; then \
echo "Server running (PID $$(cat $(PIDFILE)))"; \
curl -s http://localhost:$(PORT)/health 2>/dev/null | \
python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"Status: {d['status']}\nUptime: {d['uptime']}\")" 2>/dev/null \
|| echo "Health: unreachable"; \
else \
echo "Server not running"; \
rm -f $(PIDFILE) 2>/dev/null; \
fi
logs:
@tail -f $(LOGFILE)
dev:
flask --app src/esp32_web run --port $(PORT) --debug
flask --app src/esp32_web run --host $(HOST) --port $(PORT) --debug
test:
pytest -v
@@ -21,20 +64,21 @@ migrate-init:
migrate-create:
flask --app src/esp32_web db migrate -m "$(msg)"
# Container targets
build:
podman build -t $(APP_NAME) .
run:
container-run:
podman run -d --name $(APP_NAME) \
-p $(PORT):$(PORT) \
-p $(PORT):$(PORT)/udp \
-v ./instance:/app/instance:Z \
$(APP_NAME)
stop:
container-stop:
podman stop $(APP_NAME) && podman rm $(APP_NAME)
logs:
container-logs:
podman logs -f $(APP_NAME)
clean: