Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/root/etc/s6-overlay/s6-rc.d/gunicorn/run
Original file line number Diff line number Diff line change
Expand Up @@ -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
65 changes: 44 additions & 21 deletions tubesync/tubesync/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()