2021-03-17 20:13:58 -04:00
|
|
|
import os
|
2013-06-24 17:59:31 -07:00
|
|
|
import psutil
|
2013-03-13 23:21:30 -07:00
|
|
|
import math
|
2011-02-09 15:45:41 -05:00
|
|
|
|
2016-12-02 19:10:54 -08:00
|
|
|
GIGS_OF_MEMORY = psutil.virtual_memory().total/1024/1024/1024.
|
|
|
|
NUM_CPUS = psutil.cpu_count()
|
2011-02-09 15:45:41 -05:00
|
|
|
|
2013-03-17 16:03:02 -07:00
|
|
|
bind = "0.0.0.0:8000"
|
2013-02-25 19:01:04 -08:00
|
|
|
pidfile = "/srv/newsblur/logs/gunicorn.pid"
|
|
|
|
logfile = "/srv/newsblur/logs/production.log"
|
|
|
|
accesslog = "/srv/newsblur/logs/production.log"
|
|
|
|
errorlog = "/srv/newsblur/logs/errors.log"
|
2021-03-17 17:16:49 -04:00
|
|
|
loglevel = "info"
|
2011-02-09 15:45:41 -05:00
|
|
|
name = "newsblur"
|
2012-01-08 20:47:34 -08:00
|
|
|
timeout = 120
|
2011-10-05 10:10:30 -07:00
|
|
|
max_requests = 1000
|
2014-05-22 09:32:42 -07:00
|
|
|
x_forwarded_for_header = "X-FORWARDED-FOR"
|
2014-05-22 09:21:38 -07:00
|
|
|
forwarded_allow_ips = "*"
|
2014-10-01 15:40:33 -07:00
|
|
|
limit_request_line = 16000
|
|
|
|
limit_request_fields = 1000
|
2021-03-29 18:01:13 -04:00
|
|
|
worker_tmp_dir = "/dev/shm"
|
2021-04-03 12:28:50 -05:00
|
|
|
reload = True
|
2013-06-26 12:27:43 -07:00
|
|
|
|
2022-02-28 14:41:29 -05:00
|
|
|
workers = max(int(math.floor(GIGS_OF_MEMORY * 2)), 3)
|
2013-03-13 23:21:30 -07:00
|
|
|
|
2022-02-28 14:41:29 -05:00
|
|
|
if workers > 4:
|
|
|
|
workers = 4
|
2015-07-29 13:30:17 -07:00
|
|
|
|
2021-03-17 20:13:58 -04:00
|
|
|
if os.environ.get('DOCKERBUILD', False):
|
2021-04-07 10:36:16 -05:00
|
|
|
workers = 2
|
2022-03-31 15:34:33 -04:00
|
|
|
|
|
|
|
prom_folder = '/srv/newsblur/.prom_cache'
|
|
|
|
os.makedirs(prom_folder, exist_ok=True)
|
|
|
|
os.environ['PROMETHEUS_MULTIPROC_DIR'] = prom_folder
|
|
|
|
for filename in os.listdir(prom_folder):
|
|
|
|
file_path = os.path.join(prom_folder, filename)
|
|
|
|
try:
|
|
|
|
if os.path.isfile(file_path) or os.path.islink(file_path):
|
|
|
|
os.unlink(file_path)
|
|
|
|
elif os.path.isdir(file_path):
|
|
|
|
shutil.rmtree(file_path)
|
|
|
|
except Exception as e:
|
|
|
|
print('Failed to delete %s. Reason: %s' % (file_path, e))
|
|
|
|
|
|
|
|
from prometheus_client import multiprocess
|
|
|
|
|
|
|
|
def child_exit(server, worker):
|
|
|
|
multiprocess.mark_process_dead(worker.pid)
|