-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathrun_server.py
More file actions
39 lines (34 loc) · 1.28 KB
/
run_server.py
File metadata and controls
39 lines (34 loc) · 1.28 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
"""
C2 Server startup script
"""
import uvicorn
import os
from api.utils.env import get_env, get_env_int
C2_SERVER_HOST = get_env("C2_SERVER_HOST", "0.0.0.0")
C2_SERVER_PORT = get_env_int("C2_SERVER_PORT", 8000)
# Check production environment
IS_PRODUCTION = os.getenv("ENVIRONMENT", "development").lower() == "production"
if __name__ == "__main__":
if IS_PRODUCTION:
# Production settings
uvicorn.run(
"api.main:app",
host=C2_SERVER_HOST,
port=C2_SERVER_PORT,
workers=int(os.getenv("UVICORN_WORKERS", "4")), # Number of worker processes
log_level="warning", # Only warning and error in production
access_log=False, # Disable access log in production
loop="uvloop", # Use uvloop for better performance
http="httptools" # Use httptools
)
else:
# Development settings
# reload=False to prevent interference with background operations
# If you want auto-reload, set reload=True and manually restart server after file changes
uvicorn.run(
"api.main:app",
host=C2_SERVER_HOST,
port=C2_SERVER_PORT,
reload=False, # Disable auto-reload to prevent interference
log_level="info"
)