diff --git a/config/root/etc/s6-overlay/s6-rc.d/gunicorn/run b/config/root/etc/s6-overlay/s6-rc.d/gunicorn/run index d94a0c62a..78c058337 100755 --- a/config/root/etc/s6-overlay/s6-rc.d/gunicorn/run +++ b/config/root/etc/s6-overlay/s6-rc.d/gunicorn/run @@ -21,4 +21,4 @@ then fi exec s6-setuidgid app \ - /usr/local/bin/gunicorn -c /app/tubesync/gunicorn.py --capture-output tubesync.wsgi:application + /usr/local/bin/gunicorn --config /app/tubesync/gunicorn.py diff --git a/tubesync/tubesync/gunicorn.py b/tubesync/tubesync/gunicorn.py index 305472129..7dd522fa0 100644 --- a/tubesync/tubesync/gunicorn.py +++ b/tubesync/tubesync/gunicorn.py @@ -2,37 +2,60 @@ import multiprocessing +def get_bind(): + host = os.getenv('LISTEN_HOST', '127.0.0.1') + port = os.getenv('LISTEN_PORT', '8080') + return f'{host}:{port}' + def get_num_workers(): # Sane max workers to allow to be spawned cpu_workers = multiprocessing.cpu_count() * 2 + 1 # But default to 3 + num_workers = 3 try: - num_workers = int(os.getenv('GUNICORN_WORKERS', 3)) - except ValueError: - num_workers = cpu_workers - if 0 < num_workers < cpu_workers: - return num_workers - else: - return cpu_workers + gunicorn_workers = os.getenv('GUNICORN_WORKERS') + web_concurrency = os.getenv('WEB_CONCURRENCY') + if gunicorn_workers is not None: + try: + num_workers = int(gunicorn_workers) + except: + pass + elif web_concurrency is not None: + try: + num_workers = int(web_concurrency) + except: + pass + except: + pass + return max(1, min(num_workers, cpu_workers)) -def get_bind(): - host = os.getenv('LISTEN_HOST', '127.0.0.1') - port = os.getenv('LISTEN_PORT', '8080') - return '{}:{}'.format(host, port) +### Configuration +##### Logging +# Access logs are printed to stdout from nginx +accesslog = None +errorlog = '-' +loglevel = 'info' +capture_output = 'tubesync.wsgi:application' -workers = get_num_workers() -timeout = 90 -chdir = '/app' +##### Process +proc_name = 'gunicorn' daemon = False -control_socket_disable = True -control_socket = '/run/app/gunicorn.ctl' -pidfile = '/run/app/gunicorn.pid' user = 'app' group = 'app' -loglevel = 'info' -errorlog = '-' -accesslog = '/dev/null' # Access logs are printed to stdout from nginx -django_settings = 'django.settings' +chdir = '/app' +control_socket = '/run/app/gunicorn.ctl' +control_socket_disable = True +pidfile = '/run/app/gunicorn.pid' + +##### Server bind = get_bind() +django_settings = 'django.settings' +graceful_timeout = 120 +keepalive = 60 +max_requests = 1000 +max_requests_jitter = 100 +timeout = 90 +worker_class = 'sync' +workers = get_num_workers()