mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
72 lines
2.1 KiB
Plaintext
72 lines
2.1 KiB
Plaintext
"""
|
|
https://github.com/checktheroads/hyperglass
|
|
Guncorn configuration
|
|
"""
|
|
import os
|
|
import shutil
|
|
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 = "/tmp/hyperglass_prometheus"
|
|
|
|
|
|
def on_starting(server): # pylint: disable=unused-argument
|
|
"""Pre-startup Gunicorn Tasks"""
|
|
# Renders Jinja2 -> Sass, compiles Sass -> CSS prior to worker load
|
|
try:
|
|
import hyperglass.render
|
|
|
|
hyperglass.render.css()
|
|
print(1)
|
|
except ImportError as error_exception:
|
|
logger.error(f"Exception occurred:\n{error_exception}")
|
|
# Verify Redis is running
|
|
try:
|
|
import hyperglass.configuration
|
|
import redis
|
|
|
|
config = hyperglass.configuration.params()
|
|
|
|
redis_config = {
|
|
"host": config["general"]["redis_host"],
|
|
"port": config["general"]["redis_port"],
|
|
"charset": "utf-8",
|
|
"decode_responses": True,
|
|
"db": config["features"]["cache"]["redis_id"],
|
|
}
|
|
r_cache = redis.Redis(**redis_config)
|
|
if r_cache.set("testkey", "testvalue", ex=1):
|
|
logger.debug("Redis is working properly")
|
|
except (redis.exceptions.ConnectionError):
|
|
logger.error("Redis is not running")
|
|
raise EnvironmentError("Redis is not running")
|
|
# Prometheus multiprocessing directory
|
|
if os.path.exists(prometheus_multiproc_dir):
|
|
shutil.rmtree(prometheus_multiproc_dir)
|
|
else:
|
|
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):
|
|
"""Pre-shutdown Gunicorn Tasks"""
|
|
if os.path.exists(prometheus_multiproc_dir):
|
|
shutil.rmtree(prometheus_multiproc_dir)
|