askrobots / dbbasic-cli
Public
Make a complete, running app (a CRM, a shop, a blog) with one command, such as dbbasic crm.
stop.py · 1.3 KB · 42 lines
| 1 | """Stop DBBasic services""" |
| 2 | |
| 3 | import os |
| 4 | import signal |
| 5 | import typer |
| 6 | from rich.console import Console |
| 7 | import psutil |
| 8 | |
| 9 | from .config import SERVICES, get_pid, remove_pid |
| 10 | |
| 11 | console = Console() |
| 12 | |
| 13 | def stop(service: str = typer.Argument(None, help="Service to stop (omit for all)")): |
| 14 | """Stop DBBasic services""" |
| 15 | |
| 16 | if service and service not in SERVICES: |
| 17 | console.print(f"[red]Unknown service: {service}[/red]") |
| 18 | console.print(f"Available: {', '.join(SERVICES.keys())}") |
| 19 | raise typer.Exit(1) |
| 20 | |
| 21 | services_to_stop = [service] if service else list(SERVICES.keys()) |
| 22 | |
| 23 | for svc_name in services_to_stop: |
| 24 | svc = SERVICES[svc_name] |
| 25 | pid = get_pid(svc_name) |
| 26 | |
| 27 | if pid and psutil.pid_exists(pid): |
| 28 | try: |
| 29 | os.kill(pid, signal.SIGTERM) |
| 30 | console.print(f"✅ Stopped {svc['name']}") |
| 31 | remove_pid(svc_name) |
| 32 | except ProcessLookupError: |
| 33 | console.print(f"[yellow]{svc['name']} not running[/yellow]") |
| 34 | remove_pid(svc_name) |
| 35 | except Exception as e: |
| 36 | console.print(f"[red]❌ Failed to stop {svc['name']}: {e}[/red]") |
| 37 | else: |
| 38 | console.print(f"[dim]{svc['name']} not running[/dim]") |
| 39 | remove_pid(svc_name) |
| 40 | |
| 41 | if not service: |
| 42 | console.print("\n[bold]All services stopped[/bold]") |