1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00
checktheroads-hyperglass/hyperglass/gunicorn_config.py.example
2019-06-11 13:39:40 -07:00

51 lines
1.3 KiB
Plaintext

"""
https://github.com/checktheroads/hyperglass
Guncorn configuration
"""
import os
import multiprocessing
from logzero import logger
command = "/usr/local/bin/gunicorn"
pythonpath = "/opt/hyperglass"
bind = "[::1]:8001"
preload = True
workers = multiprocessing.cpu_count() * 2
user = "www-data"
timeout = 60
keepalive = 10
# Prometheus Multiprocessing directory, set as environment variable
prometheus_multiproc_dir = ".prometheus_multiproc_dir"
def on_starting(server): # pylint: disable=unused-argument
"""Pre-startup Gunicorn Tasks"""
try:
# Renders Jinja2 -> Sass, compiles Sass -> CSS prior to worker load
import hyperglass.render
hyperglass.render.css()
print(1)
except ImportError as error_exception:
logger.error(f"Exception occurred:\n{error_exception}")
#
os.mkdir(prometheus_multiproc_dir)
os.environ["prometheus_multiproc_dir"] = prometheus_multiproc_dir
def worker_exit(server, worker): # pylint: disable=unused-argument
"""Prometheus multiprocessing WSGI support"""
from prometheus_client import multiprocess
multiprocess.mark_process_dead(worker.pid)
def on_exit(server):
try:
import shutil
except ImportError as error_exception:
logger.error(f"Exception occurred:\n{error_exception}")
shutil.rmtree(prometheus_multiproc_dir)