From a12b15dc1d5e5cd41ef6019548a65f2553f48b77 Mon Sep 17 00:00:00 2001 From: Stephen Herr Date: Wed, 10 Jan 2024 15:06:53 -0500 Subject: [PATCH] Load gunicorn defaults before overriding with app settings fixes: #4917 --- CHANGES/4917.feature | 1 + pulpcore/app/entrypoint.py | 14 ++++++++++++-- pulpcore/content/entrypoint.py | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 CHANGES/4917.feature diff --git a/CHANGES/4917.feature b/CHANGES/4917.feature new file mode 100644 index 00000000000..5aec061a723 --- /dev/null +++ b/CHANGES/4917.feature @@ -0,0 +1 @@ +Enable the gunicorn applications for pulp-api and pulp-content to load configs from a "gunicorn.conf.py" file. diff --git a/pulpcore/app/entrypoint.py b/pulpcore/app/entrypoint.py index d99ea268276..59fef48c5c2 100644 --- a/pulpcore/app/entrypoint.py +++ b/pulpcore/app/entrypoint.py @@ -9,7 +9,7 @@ from django.db import connection from django.db.utils import InterfaceError, OperationalError from gunicorn.workers.sync import SyncWorker -from gunicorn.app.base import BaseApplication +from gunicorn.app.base import Application from pulpcore.app.apps import pulp_plugin_configs @@ -80,12 +80,22 @@ def run(self): self.api_app_status.delete() -class PulpcoreApiApplication(BaseApplication): +class PulpcoreApiApplication(Application): def __init__(self, options): self.options = options or {} super().__init__() + def init(self, *args, **kwargs): + """ + A hook for setting application-specific configs, which we instead do below in load_config + where it's non-overridable. + """ + pass + def load_config(self): + # Load default gunicorn configs, including reading from the default config file. + super().load_config() + # Override with settings that we've specified in the startup script. [ self.cfg.set(key.lower(), value) for key, value in self.options.items() diff --git a/pulpcore/content/entrypoint.py b/pulpcore/content/entrypoint.py index e158d11652d..db4b0326f0f 100644 --- a/pulpcore/content/entrypoint.py +++ b/pulpcore/content/entrypoint.py @@ -1,13 +1,23 @@ import click -from gunicorn.app.base import BaseApplication +from gunicorn.app.base import Application -class PulpcoreContentApplication(BaseApplication): +class PulpcoreContentApplication(Application): def __init__(self, options): self.options = options or {} super().__init__() + def init(self, *args, **kwargs): + """ + A hook for setting application-specific configs, which we instead do below in load_config + where it's non-overridable. + """ + pass + def load_config(self): + # Load default gunicorn configs, including reading from the default config file. + super().load_config() + # Override with settings that we've specified in the startup script. [ self.cfg.set(key.lower(), value) for key, value in self.options.items()