uWSGI example config provided
Example uWSGI, application and systemd service configuraion files added. Logging configuration added into build_app. Logging configuration is disabled for tests. Change-Id: Iff6e5e7065d513caf48f272f7e49794d2ac53d0b Closes-Bug: #1583134
This commit is contained in:
parent
83c81d41e1
commit
ef9d306c5a
|
@ -0,0 +1,4 @@
|
||||||
|
LOG_LEVEL = 'DEBUG'
|
||||||
|
|
||||||
|
SQLALCHEMY_DATABASE_URI = \
|
||||||
|
'postgresql://tuningbox:tuningbox@localhost/tuningbox'
|
|
@ -0,0 +1,8 @@
|
||||||
|
uwsgi:
|
||||||
|
socket: :8082
|
||||||
|
protocol: http
|
||||||
|
module: tuning_box.app:build_app()
|
||||||
|
pythonpath: %d../../..
|
||||||
|
env: TUNINGBOX_SETTINGS=%d/tuningbox_config.py
|
||||||
|
# logto: /var/log/tuningbox/tuningbox.log
|
||||||
|
# pid: /var/run/tuningbox.pid
|
|
@ -0,0 +1,12 @@
|
||||||
|
[Unit]
|
||||||
|
Name=Tunigbox service
|
||||||
|
ConditionPathExists=/etc/tuningbox/uwsgi_tuningbox.yaml
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/sbin/uwsgi -y /etc/tuningbox/uwsgi_tuningbox.yaml
|
||||||
|
ExecReload=/usr/sbin/uwsgi --reload /var/run/tuningbox.pid
|
||||||
|
ExecStop=/usr/sbin/uwsgi --stop /var/run/tuningbox.pid
|
||||||
|
ExecStopPost=/usr/bin/rm -f /var/run/tuningbox.pid
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -21,6 +21,7 @@ from werkzeug import exceptions
|
||||||
|
|
||||||
from tuning_box import converters
|
from tuning_box import converters
|
||||||
from tuning_box import db
|
from tuning_box import db
|
||||||
|
from tuning_box import logger
|
||||||
|
|
||||||
# These handlers work if PROPAGATE_EXCEPTIONS is off (non-Nailgun case)
|
# These handlers work if PROPAGATE_EXCEPTIONS is off (non-Nailgun case)
|
||||||
api_errors = {
|
api_errors = {
|
||||||
|
@ -290,7 +291,7 @@ def handle_integrity_error(exc):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def build_app():
|
def build_app(configure_logging=True):
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
app.url_map.converters.update(converters.ALL)
|
app.url_map.converters.update(converters.ALL)
|
||||||
api.init_app(app) # init_app spoils Api object if app is a blueprint
|
api.init_app(app) # init_app spoils Api object if app is a blueprint
|
||||||
|
@ -300,6 +301,9 @@ def build_app():
|
||||||
# These handlers work if PROPAGATE_EXCEPTIONS is on (Nailgun case)
|
# These handlers work if PROPAGATE_EXCEPTIONS is on (Nailgun case)
|
||||||
app.register_error_handler(sa_exc.IntegrityError, handle_integrity_error)
|
app.register_error_handler(sa_exc.IntegrityError, handle_integrity_error)
|
||||||
db.db.init_app(app)
|
db.db.init_app(app)
|
||||||
|
if configure_logging:
|
||||||
|
log_level = app.config.get('LOG_LEVEL', 'INFO')
|
||||||
|
logger.init_logger(log_level)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
def get_formatter():
|
||||||
|
date_format = "%Y-%m-%d %H:%M:%S"
|
||||||
|
log_format = "%(asctime)s.%(msecs)03d %(levelname)s " \
|
||||||
|
"(%(module)s) %(message)s"
|
||||||
|
return logging.Formatter(fmt=log_format, datefmt=date_format)
|
||||||
|
|
||||||
|
|
||||||
|
def init_logger(log_level):
|
||||||
|
handler = logging.StreamHandler()
|
||||||
|
handler.setFormatter(get_formatter())
|
||||||
|
logger = logging.getLogger()
|
||||||
|
logger.addHandler(handler)
|
||||||
|
logger.setLevel(log_level)
|
|
@ -43,7 +43,7 @@ class Client(testing.FlaskClient):
|
||||||
class TestApp(base.TestCase):
|
class TestApp(base.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestApp, self).setUp()
|
super(TestApp, self).setUp()
|
||||||
self.app = app.build_app()
|
self.app = app.build_app(configure_logging=False)
|
||||||
self.app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///'
|
self.app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///'
|
||||||
with self.app.app_context():
|
with self.app.app_context():
|
||||||
db.fix_sqlite()
|
db.fix_sqlite()
|
||||||
|
|
Loading…
Reference in New Issue