Skip to content

Commit ef84c84

Browse files
committed
add arg option host
Signed-off-by: Ceng2333 <[email protected]>
1 parent 9812948 commit ef84c84

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

enhanced_babysitter.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737
logger = logging.getLogger(__name__)
3838

3939
class EnhancedServiceBabysitter:
40-
def __init__(self, config_file, port, service_name=None,
40+
def __init__(self, config_file, host, port, service_name=None,
4141
registry_url="http://localhost:8081", router_url="http://localhost:8080",
4242
max_restarts=10, restart_delay=5, heartbeat_interval=30):
4343
self.config_file = config_file
44+
self.host = host
4445
self.port = port
4546
self.service_name = service_name or f"infinilm-rust-{port}"
4647
self.registry_url = registry_url
@@ -65,9 +66,9 @@ def __init__(self, config_file, port, service_name=None,
6566
# Service info
6667
self.service_info = ServiceInfo(
6768
name=self.service_name,
68-
host="localhost",
69+
host=self.host,
6970
port=self.babysitter_port,
70-
url=f"http://localhost:{self.babysitter_port}",
71+
url=f"http://{self.host}:{self.babysitter_port}",
7172
status="running",
7273
metadata={
7374
"type": "rust",
@@ -144,9 +145,9 @@ async def info_handler(self, request):
144145
"""Service info endpoint"""
145146
return web.json_response({
146147
"name": self.service_name,
147-
"host": "localhost",
148+
"host": self.host,
148149
"port": self.babysitter_port,
149-
"url": f"http://localhost:{self.babysitter_port}",
150+
"url": f"http://{self.host}:{self.babysitter_port}",
150151
"metadata": self.service_info.metadata,
151152
"xtask_port": self.xtask_port,
152153
"uptime": time.time() - getattr(self, 'start_time', time.time())
@@ -216,9 +217,9 @@ def register_xtask_with_registry(self) -> bool:
216217

217218
xtask_service_info = ServiceInfo(
218219
name=f"{self.service_name}-xtask",
219-
host="localhost",
220+
host=self.host,
220221
port=self.xtask_port,
221-
url=f"http://localhost:{self.xtask_port}",
222+
url=f"http://{self.host}:{self.xtask_port}",
222223
status="running",
223224
metadata={
224225
"type": "openai-api",
@@ -345,7 +346,7 @@ def start_service(self):
345346
def check_service_health(self) -> bool:
346347
"""Check if the service is responding to health checks"""
347348
try:
348-
response = requests.get(f"http://localhost:{self.port}/health", timeout=5)
349+
response = requests.get(f"http://{self.host}:{self.port}/health", timeout=5)
349350
return response.status_code == 200
350351
except:
351352
return False
@@ -396,6 +397,7 @@ async def run(self):
396397
logger.info("Starting Enhanced InfiniLM service babysitter...")
397398
logger.info(f"Service name: {self.service_name}")
398399
logger.info(f"Config file: {self.config_file}")
400+
logger.info(f"Host: {self.host}")
399401
logger.info(f"Port: {self.port}")
400402
logger.info(f"Registry URL: {self.registry_url}")
401403
logger.info(f"Router URL: {self.router_url}")
@@ -446,6 +448,7 @@ def main():
446448

447449
parser = argparse.ArgumentParser(description="Enhanced Babysitter for InfiniLM service with Registry integration")
448450
parser.add_argument("config_file", help="Path to the service configuration file (e.g., service.toml)")
451+
parser.add_argument("--host", default="localhost", help="Host to run the service on (default: localhost)")
449452
parser.add_argument("-p", "--port", type=int, default=5000, help="Port to run the service on (default: 5000)")
450453
parser.add_argument("-n", "--name", help="Service name (default: infinilm-rust-{port})")
451454
parser.add_argument("--registry", default="http://localhost:8081", help="Registry URL (default: http://localhost:8081)")
@@ -464,6 +467,7 @@ def main():
464467
# Create and run enhanced babysitter
465468
babysitter = EnhancedServiceBabysitter(
466469
config_file=args.config_file,
470+
host=args.host,
467471
port=args.port,
468472
service_name=args.name,
469473
registry_url=args.registry,
@@ -477,3 +481,5 @@ def main():
477481

478482
if __name__ == "__main__":
479483
main()
484+
485+
## python3 enhanced_babysitter.py service156_generated.toml --port 5002 --name service156 --registry http://172.22.163.154:8081 --router http://172.22.163.154:8080 --host 172.22.163.156

0 commit comments

Comments
 (0)