Principle:1Panel dev MaxKB Service Deployment
| Knowledge Sources | |
|---|---|
| Domains | Deployment, DevOps |
| Last Updated | 2026-10-10 00:00 GMT |
Overview
A multi-service deployment pattern that uses a single CLI entrypoint to orchestrate web, worker, and model services with environment-based configuration and database migration retry logic.
Description
MaxKB's deployment architecture centers on a single `main.py` entrypoint that manages three services:
- Web — Django/Gunicorn HTTP server serving the admin API, chat API, and SPA static files on port 8080
- Celery — Background task workers for async embedding, scheduled jobs, and long-running operations
- Local Model — Minimal Django server for the bundled sentence-transformers embedding model on port 11636
The deployment pattern includes:
- Environment-based settings dispatch — `SERVER_NAME` env var selects between full Django settings (web) and minimal settings (local_model)
- Database migration with crash recovery — Retries `migrate` up to 10 times with 5s intervals when PostgreSQL is in crash-recovery mode
- Static file collection — Collects Vue SPA build artifacts into Django's static files
- Daemon spawning — Production mode spawns gunicorn + celery as watched daemons via Django management commands
Usage
Use this principle when designing:
- Multi-service Python application deployment
- Database migration with health-check retry logic
- Environment-variable-based settings selection
Theoretical Basis
The deployment pattern follows the Single Entry Point principle with Service Separation:
# Abstract algorithm description (NOT real implementation)
def main():
configure_paths() # sys.path, DJANGO_SETTINGS_MODULE
set_server_name(services) # 'web' or 'local_model'
django.setup()
if action == 'dev':
collect_static()
run_migrations()
start_dev_server(service) # runserver or celery
elif action == 'start':
collect_static()
run_migrations()
spawn_daemons(services, workers, force) # gunicorn + celery
elif action == 'upgrade_db':
run_migrations_with_retry(max_retries=10, interval=5)
The migration retry logic detects PostgreSQL crash-recovery state by string matching on error messages (`'the database system is starting up'`, `'Connection refused'`), which addresses a gap in TCP-based health checks that report readiness before query capability.