File size: 2,072 Bytes
39b5ef2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import subprocess
import os
import sys
import time
import threading

# Define services with their directories and ports
SERVICES = [
    {"name": "Auth Service", "dir": "services/auth-service", "port": 5001},
    {"name": "File Parser", "dir": "services/file-parser-service", "port": 5002},
    {"name": "AI Service", "dir": "services/ai-service", "port": 5003},
    {"name": "Frontend", "dir": "services/frontend-service", "port": 5004},
    {"name": "API Gateway", "dir": "services/api-gateway", "port": 5000},
]

processes = []

def run_service(service):
    print(f"Starting {service['name']}...")
    cwd = os.path.join(os.getcwd(), service['dir'])
    
    # Use the current python interpreter
    cmd = [sys.executable, "app.py"]
    
    # Set environment variables if needed
    env = os.environ.copy()
    env["PORT"] = str(service["port"])
    env["NO_PROXY"] = "*" # Disable proxy for inter-service communication
    
    process = subprocess.Popen(
        cmd, 
        cwd=cwd, 
        env=env,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        text=True,
        bufsize=1
    )
    processes.append(process)
    
    # Print service logs with prefix
    for line in iter(process.stdout.readline, ""):
        print(f"[{service['name']}] {line.strip()}")
    
    process.stdout.close()

def main():
    print("🌟 AceNow Microservices Development Runner")
    print("==========================================")
    
    threads = []
    for service in SERVICES:
        t = threading.Thread(target=run_service, args=(service,))
        t.daemon = True
        t.start()
        threads.append(t)
        time.sleep(1) # Small delay to avoid clashes
    
    print("\nAll services started. Access the app at http://localhost:5000")
    print("Press Ctrl+C to stop all services.\n")
    
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("\nStopping all services...")
        for p in processes:
            p.terminate()
        sys.exit(0)

if __name__ == "__main__":
    main()