run-dev: Display ports more nicely.

Here is the new output for displaying ports:

    Zulip services will listen on ports:
       9991: web proxy
       9992: Django
       9993: Tornado
       9994: webpack
       9995: Thumbor

    Note to Vagrant users: Only the proxy port (9991) is exposed.

I tone down the yellow for the Vagrant warning, and I show
the web proxy in cyan to emphasize it.

I also extracted the code into a function, and I don't call
that function until after `app.listen()`.  (The users probably
won't notice much difference in the timing of this message, but
the message won't show if the `listen` step fails for some
reason, which I think is what we want here.)
This commit is contained in:
Steve Howell 2020-04-30 22:46:50 +00:00 committed by Tim Abbott
parent 9089fd5b08
commit 9cdc9cbca6
1 changed files with 22 additions and 12 deletions

View File

@ -100,7 +100,7 @@ os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from scripts.lib.zulip_tools import WARNING, ENDC from scripts.lib.zulip_tools import CYAN, WARNING, ENDC
proxy_port = base_port proxy_port = base_port
django_port = base_port + 1 django_port = base_port + 1
@ -325,18 +325,25 @@ def shutdown_handler(*args: Any, **kwargs: Any) -> None:
else: else:
io_loop.stop() io_loop.stop()
# log which services/ports will be started def print_listeners() -> None:
print("Starting Zulip services on ports: web proxy: {},".format(proxy_port), print("\nZulip services will listen on ports:")
"Django: {}, Tornado: {}, Thumbor: {}".format(django_port, tornado_port, thumbor_port), ports = [
end='') (proxy_port, CYAN + 'web proxy' + ENDC),
if options.test: (django_port, 'Django'),
print("") # no webpack for --test (tornado_port, 'Tornado'),
else: ]
print(", webpack: {}".format(webpack_port))
print("".join((WARNING, if not options.test:
"Note: only port {} is exposed to the host in a Vagrant environment.".format( ports.append((webpack_port, 'webpack'))
proxy_port), ENDC)))
ports.append((thumbor_port, 'Thumbor'))
for port, label in ports:
print(f' {port}: {label}')
print()
proxy_warning = f"Only the proxy port ({proxy_port}) is exposed."
print(WARNING + "Note to Vagrant users: " + ENDC + proxy_warning + '\n')
try: try:
app = Application(enable_logging=options.enable_tornado_logging) app = Application(enable_logging=options.enable_tornado_logging)
@ -346,6 +353,9 @@ try:
if e.errno == 98: if e.errno == 98:
print('\n\nERROR: You probably have another server running!!!\n\n') print('\n\nERROR: You probably have another server running!!!\n\n')
raise raise
print_listeners()
ioloop = IOLoop.instance() ioloop = IOLoop.instance()
for s in (signal.SIGINT, signal.SIGTERM): for s in (signal.SIGINT, signal.SIGTERM):
signal.signal(s, shutdown_handler) signal.signal(s, shutdown_handler)