3morixd commited on
Commit
5509816
·
verified ·
1 Parent(s): d67f56c

Upload scripts/start_all.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/start_all.py +83 -0
scripts/start_all.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ dispatchAI Startup Script - starts all services
3
+ Run this when the PC boots or after a restart.
4
+ """
5
+ import subprocess
6
+ import time
7
+ import sys
8
+ import os
9
+
10
+ BASE_DIR = "C:/Users/RAK/dispatch-ai"
11
+ VENV_PYTHON = f"{BASE_DIR}/.venv/Scripts/python.exe"
12
+ CADDY_PATH = "C:/Users/RAK/AppData/Local/Microsoft/WinGet/Packages/CaddyServer.Caddy_Microsoft.Winget.Source_8wekyb3d8bbwe/caddy.exe"
13
+
14
+ def start_service(name, command, check_url=None, wait=3):
15
+ """Start a background service."""
16
+ print(f" Starting {name}...", end=" ")
17
+ try:
18
+ proc = subprocess.Popen(
19
+ command,
20
+ stdout=subprocess.DEVNULL,
21
+ stderr=subprocess.DEVNULL,
22
+ shell=True,
23
+ )
24
+ time.sleep(wait)
25
+ if check_url:
26
+ import urllib.request
27
+ try:
28
+ urllib.request.urlopen(check_url, timeout=5)
29
+ print(f"OK (PID {proc.pid})")
30
+ except:
31
+ print(f"STARTED (PID {proc.pid}) - health check pending")
32
+ else:
33
+ print(f"OK (PID {proc.pid})")
34
+ return proc.pid
35
+ except Exception as e:
36
+ print(f"FAILED: {e}")
37
+ return None
38
+
39
+ def main():
40
+ print("=" * 50)
41
+ print("dispatchAI Startup")
42
+ print("=" * 50)
43
+
44
+ pids = {}
45
+
46
+ # 1. API Gateway
47
+ pids["gateway"] = start_service(
48
+ "API Gateway",
49
+ f'cd {BASE_DIR} && {VENV_PYTHON} -m uvicorn api.gateway:app --host 0.0.0.0 --port 8081',
50
+ check_url="http://127.0.0.1:8081/",
51
+ )
52
+
53
+ # 2. Phone Proxies
54
+ phones = ["R3CN50EY64N", "R3CN50GRK5X", "R3CN50GTEYH"]
55
+ for i, serial in enumerate(phones):
56
+ port = 5000 + i
57
+ pids[f"phone_{i}"] = start_service(
58
+ f"Phone Proxy {serial}",
59
+ f'cd {BASE_DIR} && {VENV_PYTHON} api/phone_proxy_v2.py {serial} {port}',
60
+ check_url=f"http://127.0.0.1:{port}/health",
61
+ )
62
+
63
+ # 3. Caddy (HTTPS)
64
+ pids["caddy"] = start_service(
65
+ "Caddy HTTPS",
66
+ f'"{CADDY_PATH}" run --config {BASE_DIR}/api/Caddyfile',
67
+ )
68
+
69
+ print()
70
+ print("=" * 50)
71
+ print("All services started!")
72
+ print(f" API: http://api.dispatchai.ai:8081")
73
+ print(f" HTTPS: https://api.dispatchai.ai")
74
+ print(f" Phones: 3 proxies on ports 5000-5002")
75
+ print("=" * 50)
76
+
77
+ # Save PIDs
78
+ with open(f"{BASE_DIR}/data/service_pids.json", "w") as f:
79
+ import json
80
+ json.dump(pids, f, indent=2)
81
+
82
+ if __name__ == "__main__":
83
+ main()