Add ability to listen on unix sockets

Introduces a way to tell the app to listen on unix socket instead of
host:port.

Fixes #436
main
Ben Busby 2022-04-06 14:11:52 -06:00
parent 470e2932ad
commit 0e5630f33a
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
2 changed files with 17 additions and 4 deletions

View File

@ -512,6 +512,11 @@ def run_app() -> None:
default='127.0.0.1', default='127.0.0.1',
metavar='<ip address>', metavar='<ip address>',
help='Specifies the host address to use (default 127.0.0.1)') help='Specifies the host address to use (default 127.0.0.1)')
parser.add_argument(
'--unix-socket',
default='',
metavar='</path/to/unix.sock>',
help='Listen for app on unix socket instead of host:port')
parser.add_argument( parser.add_argument(
'--debug', '--debug',
default=False, default=False,
@ -562,5 +567,7 @@ def run_app() -> None:
if args.debug: if args.debug:
app.run(host=args.host, port=args.port, debug=args.debug) app.run(host=args.host, port=args.port, debug=args.debug)
elif args.unix_socket:
waitress.serve(app, unix_socket=args.unix_socket)
else: else:
waitress.serve(app, listen="{}:{}".format(args.host, args.port)) waitress.serve(app, listen="{}:{}".format(args.host, args.port))

8
run
View File

@ -3,7 +3,7 @@
# ./run # Runs the full web app # ./run # Runs the full web app
# ./run test # Runs the testing suite # ./run test # Runs the testing suite
set -eu set -e
SCRIPT_DIR="$(CDPATH= command cd -- "$(dirname -- "$0")" && pwd -P)" SCRIPT_DIR="$(CDPATH= command cd -- "$(dirname -- "$0")" && pwd -P)"
@ -24,7 +24,13 @@ if [ "$SUBDIR" = "test" ]; then
pytest -sv pytest -sv
else else
mkdir -p "$STATIC_FOLDER" mkdir -p "$STATIC_FOLDER"
if [ ! -z "$UNIX_SOCKET" ]; then
python3 -um app \
--unix-socket "$UNIX_SOCKET"
else
python3 -um app \ python3 -um app \
--host "${ADDRESS:-0.0.0.0}" \ --host "${ADDRESS:-0.0.0.0}" \
--port "${PORT:-"${EXPOSE_PORT:-5000}"}" --port "${PORT:-"${EXPOSE_PORT:-5000}"}"
fi fi
fi