Make vitrage-api wrap uWSGI
When running vitrage-api as a standalone it uses a development server which is not suitable for production. Many use this in production if uWSGI is installed lets use uWSGI instead. if not then run the development server and print a warning Change-Id: If24a299b56c30e49d556058c18519bfee06b6e66
This commit is contained in:
parent
7fdda9f2c2
commit
c5b0d78b6f
@ -10,10 +10,14 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import math
|
||||||
import os
|
import os
|
||||||
|
from os import path
|
||||||
|
import sys
|
||||||
|
|
||||||
import pecan
|
import pecan
|
||||||
|
|
||||||
|
from distutils import spawn
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
@ -76,6 +80,45 @@ def load_app(conf):
|
|||||||
|
|
||||||
|
|
||||||
def build_server(conf):
|
def build_server(conf):
|
||||||
|
uwsgi = spawn.find_executable("uwsgi")
|
||||||
|
if not uwsgi:
|
||||||
|
LOG.warning('uwsgi not installed, starting a TEST server')
|
||||||
|
build_simple_server(conf)
|
||||||
|
else:
|
||||||
|
build_uwsgi_server(conf, uwsgi)
|
||||||
|
|
||||||
|
|
||||||
|
def wsgi_file():
|
||||||
|
return path.join(path.dirname(__file__), 'app.wsgi')
|
||||||
|
|
||||||
|
|
||||||
|
def build_uwsgi_server(conf, uwsgi):
|
||||||
|
|
||||||
|
args = [
|
||||||
|
"--if-not-plugin", "python", "--plugin", "python", "--endif",
|
||||||
|
"--http-socket", "%s:%d" % (conf.api.host, conf.api.port),
|
||||||
|
"--master",
|
||||||
|
"--enable-threads",
|
||||||
|
"--thunder-lock",
|
||||||
|
"--hook-master-start", "unix_signal:15 gracefully_kill_them_all",
|
||||||
|
"--die-on-term",
|
||||||
|
"--processes", str(math.floor(conf.api.workers * 1.5)),
|
||||||
|
"--threads", str(conf.api.workers),
|
||||||
|
"--lazy-apps",
|
||||||
|
"--chdir", "/",
|
||||||
|
"--wsgi-file", wsgi_file(),
|
||||||
|
"--procname-prefix", "vitrage",
|
||||||
|
"--pyargv", " ".join(sys.argv[1:]),
|
||||||
|
]
|
||||||
|
|
||||||
|
virtual_env = os.getenv("VIRTUAL_ENV")
|
||||||
|
if virtual_env is not None:
|
||||||
|
args.extend(["-H", os.getenv("VIRTUAL_ENV", ".")])
|
||||||
|
|
||||||
|
return os.execl(uwsgi, uwsgi, *args)
|
||||||
|
|
||||||
|
|
||||||
|
def build_simple_server(conf):
|
||||||
app = load_app(conf)
|
app = load_app(conf)
|
||||||
# Create the WSGI server and start it
|
# Create the WSGI server and start it
|
||||||
host, port = conf.api.host, conf.api.port
|
host, port = conf.api.host, conf.api.port
|
||||||
@ -92,6 +135,8 @@ def build_server(conf):
|
|||||||
LOG.info('serving on http://%(host)s:%(port)s',
|
LOG.info('serving on http://%(host)s:%(port)s',
|
||||||
{'host': host, 'port': port})
|
{'host': host, 'port': port})
|
||||||
|
|
||||||
|
LOG.info('"DANGER! For testing only, do not use in production"')
|
||||||
|
|
||||||
serving.run_simple(host, port,
|
serving.run_simple(host, port,
|
||||||
app, processes=conf.api.workers)
|
app, processes=conf.api.workers)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user