提交 6bb9c11c 编写于 作者: L Li Hongzhang

show all accessible ip addresses when started

上级 60aa5e29
...@@ -14,19 +14,18 @@ ...@@ -14,19 +14,18 @@
# ============================================================================ # ============================================================================
"""Web service entrance.""" """Web service entrance."""
import os import os
import stat
import re import re
import shlex
import socket
import stat
import subprocess import subprocess
import time import time
import shlex
from gunicorn.glogging import Logger from gunicorn.glogging import Logger
from mindinsight.backend.config import WEB_CONFIG_DIR from mindinsight.backend.config import WEB_CONFIG_DIR
from mindinsight.conf import settings from mindinsight.conf import settings
from mindinsight.utils.log import setup_logger from mindinsight.utils.log import setup_logger
MINDBOARD_APP_MODULE = "mindinsight.backend.application:APP" MINDBOARD_APP_MODULE = "mindinsight.backend.application:APP"
GUNICORN_LOGGER = "mindinsight.backend.run.GunicornLogger" GUNICORN_LOGGER = "mindinsight.backend.run.GunicornLogger"
...@@ -210,6 +209,22 @@ class GunicornLogger(Logger): ...@@ -210,6 +209,22 @@ class GunicornLogger(Logger):
os.chmod(error_log_path, stat.S_IREAD | stat.S_IWRITE) os.chmod(error_log_path, stat.S_IREAD | stat.S_IWRITE)
def _get_all_ip_addresses(host):
"""Get all the accessible IP address."""
localhost, hostname = '127.0.0.1', socket.gethostname()
_, _, ip_addresses = socket.gethostbyname_ex(hostname)
if localhost in ip_addresses:
ip_addresses.remove(localhost)
yield localhost
if host == localhost:
return
if host not in ip_addresses:
yield from ip_addresses
else:
yield host
def start(): def start():
"""Start web service.""" """Start web service."""
errorlog_abspath = _get_error_log_path() errorlog_abspath = _get_error_log_path()
...@@ -251,7 +266,11 @@ def start(): ...@@ -251,7 +266,11 @@ def start():
else: else:
state_result = _check_server_start_stat(errorlog_abspath, log_size) state_result = _check_server_start_stat(errorlog_abspath, log_size)
# print gunicorn start state to stdout # print gunicorn start state to stdout
console.info('Web address: http://%s:%s%s', settings.HOST, settings.PORT, settings.URL_PATH_PREFIX) label = 'Web address:'
for ip in _get_all_ip_addresses(settings.HOST):
format_args = label, ip, str(settings.PORT), settings.URL_PATH_PREFIX
console.info('%s http://%s:%s%s', *format_args)
label = '.' * len(label)
for line in state_result["prompt_message"]: for line in state_result["prompt_message"]:
console.info(line) console.info(line)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册