mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: support gunicorn in aurweb.spawn
This also comes with a -w|--workers argument that allows the caller to set the number of gunicorn workers. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
82ca4ad9a0
commit
47d0df76e6
1 changed files with 25 additions and 7 deletions
|
@ -29,6 +29,7 @@ children = []
|
||||||
temporary_dir = None
|
temporary_dir = None
|
||||||
verbosity = 0
|
verbosity = 0
|
||||||
asgi_backend = ''
|
asgi_backend = ''
|
||||||
|
workers = 1
|
||||||
|
|
||||||
PHP_BINARY = os.environ.get("PHP_BINARY", "php")
|
PHP_BINARY = os.environ.get("PHP_BINARY", "php")
|
||||||
PHP_MODULES = ["pdo_mysql", "pdo_sqlite"]
|
PHP_MODULES = ["pdo_mysql", "pdo_sqlite"]
|
||||||
|
@ -152,12 +153,25 @@ def start():
|
||||||
spawn_child(["php", "-S", php_address, "-t", htmldir])
|
spawn_child(["php", "-S", php_address, "-t", htmldir])
|
||||||
|
|
||||||
# FastAPI
|
# FastAPI
|
||||||
host, port = aurweb.config.get("fastapi", "bind_address").rsplit(":", 1)
|
fastapi_host, fastapi_port = aurweb.config.get(
|
||||||
if asgi_backend == "hypercorn":
|
"fastapi", "bind_address").rsplit(":", 1)
|
||||||
portargs = ["-b", f"{host}:{port}"]
|
|
||||||
elif asgi_backend == "uvicorn":
|
# Logging config.
|
||||||
portargs = ["--host", host, "--port", port]
|
aurwebdir = aurweb.config.get("options", "aurwebdir")
|
||||||
spawn_child(["python", "-m", asgi_backend] + portargs + ["aurweb.asgi:app"])
|
fastapi_log_config = os.path.join(aurwebdir, "logging.conf")
|
||||||
|
|
||||||
|
backend_args = {
|
||||||
|
"hypercorn": ["-b", f"{fastapi_host}:{fastapi_port}"],
|
||||||
|
"uvicorn": ["--host", fastapi_host, "--port", fastapi_port],
|
||||||
|
"gunicorn": ["--bind", f"{fastapi_host}:{fastapi_port}",
|
||||||
|
"-k", "uvicorn.workers.UvicornWorker",
|
||||||
|
"-w", str(workers)]
|
||||||
|
}
|
||||||
|
backend_args = backend_args.get(asgi_backend)
|
||||||
|
spawn_child([
|
||||||
|
"python", "-m", asgi_backend,
|
||||||
|
"--log-config", fastapi_log_config,
|
||||||
|
] + backend_args + ["aurweb.asgi:app"])
|
||||||
|
|
||||||
# nginx
|
# nginx
|
||||||
spawn_child(["nginx", "-p", temporary_dir, "-c", generate_nginx_config()])
|
spawn_child(["nginx", "-p", temporary_dir, "-c", generate_nginx_config()])
|
||||||
|
@ -230,8 +244,11 @@ if __name__ == '__main__':
|
||||||
description='Start aurweb\'s test server.')
|
description='Start aurweb\'s test server.')
|
||||||
parser.add_argument('-v', '--verbose', action='count', default=0,
|
parser.add_argument('-v', '--verbose', action='count', default=0,
|
||||||
help='increase verbosity')
|
help='increase verbosity')
|
||||||
parser.add_argument('-b', '--backend', choices=['hypercorn', 'uvicorn'], default='hypercorn',
|
choices = ['hypercorn', 'gunicorn', 'uvicorn']
|
||||||
|
parser.add_argument('-b', '--backend', choices=choices, default='uvicorn',
|
||||||
help='asgi backend used to launch the python server')
|
help='asgi backend used to launch the python server')
|
||||||
|
parser.add_argument("-w", "--workers", default=1, type=int,
|
||||||
|
help="number of workers to use in gunicorn")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -242,6 +259,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
verbosity = args.verbose
|
verbosity = args.verbose
|
||||||
asgi_backend = args.backend
|
asgi_backend = args.backend
|
||||||
|
workers = args.workers
|
||||||
with tempfile.TemporaryDirectory(prefix="aurweb-") as tmpdirname:
|
with tempfile.TemporaryDirectory(prefix="aurweb-") as tmpdirname:
|
||||||
temporary_dir = tmpdirname
|
temporary_dir = tmpdirname
|
||||||
start()
|
start()
|
||||||
|
|
Loading…
Add table
Reference in a new issue