blob: e56bd043a40c3d0797d366ce69f9abba28d6a22f [file] [log] [blame]
Bartosz Stebelf5b1a212023-02-04 23:47:44 +01001import os
2import gunicorn.app.base
3from django.core.wsgi import get_wsgi_application
4
5
6class StandaloneApplication(gunicorn.app.base.BaseApplication):
7
8 def __init__(self, app, options=None):
9 self.options = options or {}
10 self.application = app
11 super().__init__()
12
13 def load_config(self):
14 config = {key: value for key, value in self.options.items()
15 if key in self.cfg.settings and value is not None}
16 for key, value in config.items():
17 self.cfg.set(key.lower(), value)
18
19 def load(self):
20 return self.application
21
22
23def main():
24 options = {
25 'bind': os.environ.get('BIND_ADDR', '127.0.0.1:8080'),
26 'workers': int(os.environ.get("GUNICORN_WORKERS", "4")),
27 'capture_output': True,
28 'disable_redirect_access_to_syslog': True,
29 'accesslog': '-',
30 'errorlog': '-',
31 }
32 os.environ['DJANGO_SETTINGS_MODULE'] = "settings"
33 application = get_wsgi_application()
34 StandaloneApplication(application, options).run()
35
36
37if __name__ == '__main__':
38 main()