diff --git a/Headphones.py b/Headphones.py index dc956a43..e4506797 100755 --- a/Headphones.py +++ b/Headphones.py @@ -81,6 +81,8 @@ def main(): help='Prevent browser from launching on startup') parser.add_argument( '--pidfile', help='Create a pid file (only relevant when running as a daemon)') + parser.add_argument( + '--host', help='Specify a host (default - localhost)') args = parser.parse_args() @@ -170,6 +172,13 @@ def main(): else: http_port = int(headphones.CONFIG.HTTP_PORT) + # Force the http host if neccessary + if args.host: + http_host = args.host + logger.info('Using forced web server host: %s', http_host) + else: + http_host = headphones.CONFIG.HTTP_HOST + # Check if pyOpenSSL is installed. It is required for certificate generation # and for CherryPy. if headphones.CONFIG.ENABLE_HTTPS: @@ -183,7 +192,7 @@ def main(): # Try to start the server. Will exit here is address is already in use. web_config = { 'http_port': http_port, - 'http_host': headphones.CONFIG.HTTP_HOST, + 'http_host': http_host, 'http_root': headphones.CONFIG.HTTP_ROOT, 'http_proxy': headphones.CONFIG.HTTP_PROXY, 'enable_https': headphones.CONFIG.ENABLE_HTTPS, diff --git a/init-scripts/init.ubuntu b/init-scripts/init.ubuntu index c4c0b8dc..47f2f2b4 100755 --- a/init-scripts/init.ubuntu +++ b/init-scripts/init.ubuntu @@ -33,6 +33,7 @@ ## PYTHON_BIN= #$DAEMON, the location of the python binary, the default is /usr/bin/python ## HP_OPTS= #$EXTRA_DAEMON_OPTS, extra cli option for headphones, i.e. " --config=/home/headphones/config.ini" ## HP_PORT= #$PORT_OPTS, hardcoded port for the webserver, overrides value in config.ini +## HP_HOST= #$HOST_OPTS, host for the webserver, overrides value in config.ini ## ## EXAMPLE if want to run as different user ## add HP_USER=username to /etc/default/headphones @@ -105,7 +106,12 @@ load_settings() { PORT_OPTS=" --port=${HP_PORT} " } - DAEMON_OPTS=" Headphones.py --quiet --daemon --nolaunch --pidfile=${PID_FILE} --datadir=${DATA_DIR} ${PORT_OPTS}${EXTRA_DAEMON_OPTS}" + # Host config + [ -n "$HP_HOST" ] && { + HOST_OPTS=" --host=${HP_HOST} " + } + + DAEMON_OPTS=" Headphones.py --quiet --daemon --nolaunch --pidfile=${PID_FILE} --datadir=${DATA_DIR} ${PORT_OPTS} ${HOST_OPTS} ${EXTRA_DAEMON_OPTS}" SETTINGS_LOADED=TRUE fi