2019-06-07 18:33:49 -07:00
|
|
|
"""
|
|
|
|
https://github.com/checktheroads/hyperglass
|
|
|
|
Guncorn configuration
|
|
|
|
"""
|
2019-06-11 13:39:40 -07:00
|
|
|
import os
|
2019-05-11 23:22:27 -07:00
|
|
|
import multiprocessing
|
2019-06-11 13:39:40 -07:00
|
|
|
from logzero import logger
|
2019-05-11 23:22:27 -07:00
|
|
|
|
|
|
|
command = "/usr/local/bin/gunicorn"
|
2019-05-28 14:14:42 -07:00
|
|
|
pythonpath = "/opt/hyperglass"
|
2019-05-11 23:22:27 -07:00
|
|
|
bind = "[::1]:8001"
|
2019-05-28 14:14:42 -07:00
|
|
|
preload = True
|
2019-05-28 00:53:45 -07:00
|
|
|
workers = multiprocessing.cpu_count() * 2
|
2019-05-11 23:22:27 -07:00
|
|
|
user = "www-data"
|
2019-05-11 23:28:13 -07:00
|
|
|
timeout = 60
|
2019-05-28 14:14:42 -07:00
|
|
|
keepalive = 10
|
|
|
|
|
2019-06-11 13:39:40 -07:00
|
|
|
# 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)
|
|
|
|
|
2019-05-28 14:14:42 -07:00
|
|
|
|
2019-06-11 13:39:40 -07:00
|
|
|
def on_exit(server):
|
|
|
|
try:
|
|
|
|
import shutil
|
|
|
|
except ImportError as error_exception:
|
|
|
|
logger.error(f"Exception occurred:\n{error_exception}")
|
2019-05-28 14:14:42 -07:00
|
|
|
|
2019-06-11 13:39:40 -07:00
|
|
|
shutil.rmtree(prometheus_multiproc_dir)
|