2019-07-15 02:30:42 -07:00
|
|
|
"""
|
|
|
|
Hyperglass web app initiator. Launches Sanic with appropriate number of
|
|
|
|
workers per their documentation (equal to number of CPU cores).
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Override web server listen host & port if necessary:
|
|
|
|
host = "localhost"
|
|
|
|
port = 8001
|
|
|
|
|
|
|
|
try:
|
|
|
|
import multiprocessing
|
2019-07-29 22:13:11 -07:00
|
|
|
import os
|
|
|
|
import tempfile
|
2019-07-15 02:30:42 -07:00
|
|
|
from hyperglass import render
|
|
|
|
from hyperglass import hyperglass
|
|
|
|
from hyperglass.configuration import params
|
|
|
|
except ImportError as import_error:
|
|
|
|
raise RuntimeError(import_error)
|
|
|
|
|
2019-07-29 22:13:11 -07:00
|
|
|
debug = False
|
|
|
|
access_log = True
|
|
|
|
|
2019-07-15 02:30:42 -07:00
|
|
|
if params.general.debug:
|
|
|
|
debug = True
|
|
|
|
access_log = False
|
|
|
|
|
|
|
|
# Override the number of web server workers if necessary:
|
|
|
|
workers = multiprocessing.cpu_count()
|
|
|
|
|
|
|
|
|
|
|
|
def start():
|
|
|
|
"""
|
|
|
|
Compiles configured Sass variables to CSS, then starts Sanic web
|
|
|
|
server.
|
|
|
|
"""
|
2019-08-06 01:09:55 -07:00
|
|
|
# try:
|
|
|
|
# render.css()
|
|
|
|
# except Exception as render_error:
|
|
|
|
# raise RuntimeError(render_error)
|
2019-07-29 22:13:11 -07:00
|
|
|
|
|
|
|
tempdir = tempfile.TemporaryDirectory(prefix="hyperglass_")
|
|
|
|
os.environ["prometheus_multiproc_dir"] = tempdir.name
|
|
|
|
|
2019-07-15 02:30:42 -07:00
|
|
|
try:
|
|
|
|
hyperglass.app.run(
|
|
|
|
host=host,
|
|
|
|
port=port,
|
|
|
|
debug=params.general.debug,
|
|
|
|
workers=workers,
|
|
|
|
access_log=access_log,
|
|
|
|
)
|
|
|
|
except Exception as hyperglass_error:
|
|
|
|
raise RuntimeError(hyperglass_error)
|
|
|
|
|
|
|
|
|
|
|
|
app = start()
|