forked from TheCodeVerseHub/Miku
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_all.py
More file actions
57 lines (49 loc) · 1.4 KB
/
Copy pathstart_all.py
File metadata and controls
57 lines (49 loc) · 1.4 KB
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
"""
Start both Discord bot and API server concurrently
"""
import multiprocessing
import asyncio
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def run_bot():
"""Run the Discord bot"""
print("Starting Discord bot...")
import sys
import os
# Add src to path so cogs can be imported
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from bot import main
asyncio.run(main())
def run_api():
"""Run the FastAPI server"""
print("Starting API server...")
import uvicorn
from src.api_server import app
port = int(os.getenv("API_PORT", "8000"))
uvicorn.run(app, host="0.0.0.0", port=port, log_level="info")
def main():
"""Start both processes"""
print("=" * 50)
print("Miku Bot - Starting Services")
print("=" * 50)
# Start API server in a separate process
api_process = multiprocessing.Process(target=run_api, name="API-Server")
api_process.daemon = True
api_process.start()
print("✓ API Server started")
try:
# Run bot in main process
run_bot()
except KeyboardInterrupt:
print("\nShutting down...")
finally:
# Cleanup
api_process.terminate()
api_process.join(timeout=5)
if api_process.is_alive():
api_process.kill()
print("✓ All services stopped")
if __name__ == "__main__":
main()