Make a complete, running app (a CRM, a shop, a blog) with one command, such as dbbasic crm.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-cli.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-cli.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-cli.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Version 0.1.2: Working instant apps! a36b93a 1 year, 2 months ago History
start.py · 2.8 KB · 75 lines
1"""Start DBBasic services"""
2
3import subprocess
4import time
5from pathlib import Path
6import typer
7from rich.console import Console
8from rich.progress import Progress, SpinnerColumn, TextColumn
9import psutil
10
11from .config import SERVICES, DBBASIC_DIR, save_pid, get_pid
12
13console = Console()
14
15def start(service: str = typer.Argument(None, help="Service to start (omit for all)")):
16 """Start DBBasic services"""
17
18 if service and service not in SERVICES:
19 console.print(f"[red]Unknown service: {service}[/red]")
20 console.print(f"Available: {', '.join(SERVICES.keys())}")
21 raise typer.Exit(1)
22
23 services_to_start = [service] if service else list(SERVICES.keys())
24
25 with Progress(
26 SpinnerColumn(),
27 TextColumn("[progress.description]{task.description}"),
28 console=console,
29 ) as progress:
30
31 for svc_name in services_to_start:
32 svc = SERVICES[svc_name]
33 task = progress.add_task(f"Starting {svc['name']}...", total=1)
34
35 # Check if already running
36 pid = get_pid(svc_name)
37 if pid and psutil.pid_exists(pid):
38 progress.update(task, description=f"[yellow]{svc['name']} already running[/yellow]")
39 progress.advance(task)
40 continue
41
42 # Start the service
43 try:
44 process = subprocess.Popen(
45 ["python", f"{svc['module']}.py"],
46 cwd=str(DBBASIC_DIR),
47 stdout=subprocess.DEVNULL,
48 stderr=subprocess.DEVNULL,
49 start_new_session=True
50 )
51
52 # Save PID
53 save_pid(svc_name, process.pid)
54
55 # Wait a moment to check if it started
56 time.sleep(1)
57
58 if process.poll() is None:
59 progress.update(task, description=f"[green]✅ {svc['name']} started on port {svc['port']}[/green]")
60 else:
61 progress.update(task, description=f"[red]❌ {svc['name']} failed to start[/red]")
62
63 except Exception as e:
64 progress.update(task, description=f"[red]❌ {svc['name']}: {str(e)}[/red]")
65
66 progress.advance(task)
67
68 # Show summary
69 if not service:
70 console.print("\n[bold green]DBBasic services started![/bold green]")
71 console.print("\nAccess points:")
72 console.print(f" 📊 Dashboard: http://localhost:{SERVICES['monitor']['port']}")
73 console.print(f" 🔧 CRUD Engine: http://localhost:{SERVICES['crud']['port']}")
74 console.print(f" 📚 API Docs: http://localhost:{SERVICES['crud']['port']}/docs")
75 console.print("\nRun [bold]dbbasic status[/bold] to check service health")