From 279f8054480740ce8325f84fce7abed039cdfc0c Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 3 Oct 2016 16:36:38 -0700 Subject: [PATCH] run-dev: Automate passing --interface='' for vagrant environment. Fixes #877. --- docs/brief-install-vagrant-dev.md | 8 +------- docs/dev-env-first-time-contributors.md | 4 ++-- tools/run-dev.py | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/brief-install-vagrant-dev.md b/docs/brief-install-vagrant-dev.md index 7d2025c720..fc7ab0f3e8 100644 --- a/docs/brief-install-vagrant-dev.md +++ b/docs/brief-install-vagrant-dev.md @@ -62,18 +62,12 @@ Once that finishes, you can run the development server as follows: ``` vagrant ssh # Now inside the container -/srv/zulip/tools/run-dev.py --interface='' +/srv/zulip/tools/run-dev.py ``` To get shell access to the virtual machine running the server to run lint, management commands, etc., use `vagrant ssh`. -(A small note on tools/run-dev.py: the `--interface=''` option will -make the development server listen on all network interfaces. While -this is correct for the Vagrant guest sitting behind a NAT, you -probably don't want to use that option when using run-dev.py in other -environments). - At this point you should [read about using the development environment][using-dev]. diff --git a/docs/dev-env-first-time-contributors.md b/docs/dev-env-first-time-contributors.md index f52df5421a..2ba7e443e4 100644 --- a/docs/dev-env-first-time-contributors.md +++ b/docs/dev-env-first-time-contributors.md @@ -300,7 +300,7 @@ Next, start the Zulip server: ``` (zulip-venv)vagrant@vagrant-ubuntu-trusty-64:~ $ -/srv/zulip/tools/run-dev.py --interface='' +/srv/zulip/tools/run-dev.py ``` As you can see above the application's root directory, where you can @@ -477,7 +477,7 @@ server: christie@win10 ~/zulip $ vagrant up $ vagrant ssh -/srv/zulip/tools/run-dev.py --interface='' +/srv/zulip/tools/run-dev.py ``` #### Next Steps diff --git a/tools/run-dev.py b/tools/run-dev.py index d9b313020f..5f2e99cf6b 100755 --- a/tools/run-dev.py +++ b/tools/run-dev.py @@ -2,6 +2,7 @@ from __future__ import print_function import optparse +import pwd import subprocess import signal import traceback @@ -57,7 +58,7 @@ parser.add_option('--test', parser.add_option('--interface', action='store', dest='interface', - default='127.0.0.1', help='Set the IP or hostname for the proxy to listen on') + default=None, help='Set the IP or hostname for the proxy to listen on') parser.add_option('--no-clear-memcached', action='store_false', dest='clear_memcached', @@ -65,6 +66,18 @@ parser.add_option('--no-clear-memcached', (options, args) = parser.parse_args() +if options.interface is None: + user_id = os.getuid() + user_name = pwd.getpwuid(user_id).pw_name + if user_name == "vagrant": + # In the Vagrant development environment, we need to listen on + # all ports, and it's safe to do so, because Vagrant is only + # exposing certain guest ports (by default just 9991) to the host. + options.interface = "" + else: + # Otherwise, only listen to requests on localhost for security. + options.interface = "127.0.0.1" + base_port = 9991 if options.test: base_port = 9981