-
Notifications
You must be signed in to change notification settings - Fork 769
Expand file tree
/
Copy pathbootstrap.py
More file actions
80 lines (64 loc) · 2.06 KB
/
bootstrap.py
File metadata and controls
80 lines (64 loc) · 2.06 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.
# SPDX-License-Identifier: Apache-2.0
"""Bootstrap script for OpenViking HTTP Server."""
import argparse
import os
import uvicorn
from openviking.server.app import create_app
from openviking.server.config import load_server_config
from openviking_cli.utils.logger import configure_uvicorn_logging
def _get_version() -> str:
try:
from openviking import __version__
return __version__
except ImportError:
return "unknown"
def main():
"""Main entry point for openviking-server command."""
parser = argparse.ArgumentParser(
description="OpenViking HTTP Server",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"--version",
action="version",
version=f"openviking-server {_get_version()}",
)
parser.add_argument(
"--host",
type=str,
default=None,
help="Host to bind to",
)
parser.add_argument(
"--port",
type=int,
default=None,
help="Port to bind to",
)
parser.add_argument(
"--config",
type=str,
default=None,
help="Path to ov.conf config file",
)
args = parser.parse_args()
# Set OPENVIKING_CONFIG_FILE environment variable if --config is provided
# This allows OpenVikingConfigSingleton to load from the specified config file
if args.config is not None:
os.environ["OPENVIKING_CONFIG_FILE"] = args.config
# Load server config from ov.conf
config = load_server_config(args.config)
# Override with command line arguments
if args.host is not None:
config.host = args.host
if args.port is not None:
config.port = args.port
# Configure logging for Uvicorn
configure_uvicorn_logging()
# Create and run app
app = create_app(config)
print(f"OpenViking HTTP Server is running on {config.host}:{config.port}")
uvicorn.run(app, host=config.host, port=config.port, log_config=None)
if __name__ == "__main__":
main()