From 4d642f849aa7f28b472fa161c99be2c7ab948f1d Mon Sep 17 00:00:00 2001 From: Bryan Strassner Date: Tue, 27 Mar 2018 08:54:05 -0500 Subject: [PATCH] [fix] Add uwsgi entrypoint options Changes the entrypoint.sh options for uwsgi to include: -b 32768 : for larger header/url handling --die-on-term : for more 'normal' handling of SIGTERM --lazy-apps : to delay init of python until after forking workers --master : to provide a master process for handling request dispatch The purpose of these changes is intended to avoid some crash behavior that is occuring when the process being forked has an open db connection. The --lazy-apps option should delay initialization. The other options are recommended by uwsgi documentation, specicially the --master option. The larger buffer size is not strictly recommended, but matters when large headers are included. The die-on-term option should provide better behavior in the container environment. Related-Change: I60adeffff5461fdda957124232bc5a606baae413 Change-Id: I70510246576a8fb6aa216e7c9c7e97c1c9ab791c --- deckhand/control/api.py | 1 - deckhand/db/sqlalchemy/models.py | 24 ++++++------------- .../unit/control/test_api_initialization.py | 1 - entrypoint.sh | 14 +++++++---- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/deckhand/control/api.py b/deckhand/control/api.py index d8d2cf16..b58daba0 100644 --- a/deckhand/control/api.py +++ b/deckhand/control/api.py @@ -63,7 +63,6 @@ def init_application(): LOG.debug('Starting WSGI application using %s configuration file.', paste_file) - db_api.drop_db() db_api.setup_db(CONF.database.connection) app = deploy.loadapp('config:%s' % paste_file, name='deckhand_api') diff --git a/deckhand/db/sqlalchemy/models.py b/deckhand/db/sqlalchemy/models.py index 743de212..100e5709 100644 --- a/deckhand/db/sqlalchemy/models.py +++ b/deckhand/db/sqlalchemy/models.py @@ -211,30 +211,20 @@ def __build_tables(blob_type_obj, blob_type_list): def register_models(engine, connection_string): + global BASE + blob_types = ((JSONB, JSONB) if 'postgresql' in connection_string else (PickleType, oslo_types.JsonEncodedList())) - LOG.debug('Instantiating DB tables using %s, %s as the column type for ' - 'dictionaries, lists.', *blob_types) + LOG.debug('Instantiating DB tables using %s, %s as the column type ' + 'for dictionaries, lists.', *blob_types) - """Create database tables for all models with the given engine.""" __build_tables(*blob_types) - - this_module = sys.modules[__name__] - models = ['Bucket', 'Document', 'RevisionTag', 'Revision', 'Validation'] - - for model_name in models: - if hasattr(this_module, model_name): - model = getattr(this_module, model_name) - model.metadata.create_all(engine) + BASE.metadata.create_all(engine) def unregister_models(engine): """Drop database tables for all models with the given engine.""" - this_module = sys.modules[__name__] - models = ['Bucket', 'Document', 'RevisionTag', 'Revision', 'Validation'] + global BASE - for model_name in models: - if hasattr(this_module, model_name): - model = getattr(this_module, model_name) - model.metadata.drop_all(engine) + BASE.metadata.drop_all(engine) diff --git a/deckhand/tests/unit/control/test_api_initialization.py b/deckhand/tests/unit/control/test_api_initialization.py index 374b8d49..4e399c5e 100644 --- a/deckhand/tests/unit/control/test_api_initialization.py +++ b/deckhand/tests/unit/control/test_api_initialization.py @@ -105,6 +105,5 @@ class TestApi(test_base.DeckhandTestCase): mock.call('/versions', self.versions_resource()) ], any_order=True) - mock_db_api.drop_db.assert_called_once_with() mock_db_api.setup_db.assert_called_once_with( str(mock.sentinel.db_connection)) diff --git a/entrypoint.sh b/entrypoint.sh index 20201301..f0a9cea0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -36,12 +36,16 @@ DECKHAND_CONFIG_DIR=${DECKHAND_CONFIG_DIR:-"/etc/deckhand/deckhand.conf"} # Start deckhand application exec uwsgi \ - --http :${PORT} \ - -w deckhand.cmd \ + -b 32768 \ --callable deckhand_callable \ - --http-timeout $DECKHAND_API_TIMEOUT \ + --die-on-term \ --enable-threads \ + --http :${PORT} \ + --http-timeout $DECKHAND_API_TIMEOUT \ -L \ - --pyargv "--config-file /etc/deckhand/deckhand.conf" \ + --lazy-apps \ + --master \ + --pyargv "--config-file ${DECKHAND_CONFIG_DIR}/deckhand.conf" \ --threads $DECKHAND_API_THREADS \ - --workers $DECKHAND_API_WORKERS + --workers $DECKHAND_API_WORKERS \ + -w deckhand.cmd