Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:1Panel dev MaxKB Service Deployment

From Leeroopedia
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.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment