From 5ff62c97b69ac5352734f87e7ec4a764cfcade97 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Tue, 6 Dec 2016 19:18:14 -0500 Subject: [PATCH 1/4] uwsgi auto-reload on logging change --- Makefile | 2 +- awx/main/tasks.py | 11 +++++------ awx/settings/defaults.py | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 2e29eb174d..496b520775 100644 --- a/Makefile +++ b/Makefile @@ -406,7 +406,7 @@ uwsgi: collectstatic @if [ "$(VENV_BASE)" ]; then \ . $(VENV_BASE)/tower/bin/activate; \ fi; \ - uwsgi -b 32768 --socket :8050 --module=awx.wsgi:application --home=/venv/tower --chdir=/tower_devel/ --vacuum --processes=5 --harakiri=60 --master --no-orphans --py-autoreload 1 --max-requests=1000 --stats /tmp/stats.socket + uwsgi -b 32768 --socket :8050 --module=awx.wsgi:application --home=/venv/tower --chdir=/tower_devel/ --vacuum --processes=5 --harakiri=60 --master --no-orphans --py-autoreload 1 --max-requests=1000 --stats /tmp/stats.socket --master-fifo=/tmp/awxfifo daphne: @if [ "$(VENV_BASE)" ]; then \ diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 5e78750f3a..7ca90949a1 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -85,6 +85,10 @@ def celery_startup(conf=None, **kwargs): logger.error("Failed to rebuild schedule {}: {}".format(sch, e)) +def uwsgi_reload(): + os.system("echo r > /tmp/awxfifo") + + @task(queue='broadcast_all') def clear_cache_keys(cache_keys): set_of_keys = set([key for key in cache_keys]) @@ -92,12 +96,7 @@ def clear_cache_keys(cache_keys): cache.delete_many(set_of_keys) for setting_key in set_of_keys: if setting_key.startswith('LOG_AGGREGATOR_'): - LOGGING = settings.LOGGING - if settings.LOG_AGGREGATOR_ENABLED: - LOGGING['handlers']['http_receiver']['class'] = 'awx.main.utils.handlers.HTTPSHandler' - else: - LOGGING['handlers']['http_receiver']['class'] = 'awx.main.utils.handlers.HTTPSNullHandler' - configure_logging(settings.LOGGING_CONFIG, LOGGING) + uwsgi_reload() break diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 6aa30f252b..b9fa948521 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -999,7 +999,7 @@ LOGGING = { 'propagate': False, }, 'awx.analytics': { - 'handlers': ['null'], + 'handlers': ['http_receiver'], 'level': 'INFO', 'propagate': False }, From 431dcc6490c2d25d73ae658d58a682c432dc0638 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Fri, 9 Dec 2016 15:38:38 -0500 Subject: [PATCH 2/4] switch to smoother chain reloading --- Makefile | 2 +- awx/main/tasks.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 496b520775..8bf3766abd 100644 --- a/Makefile +++ b/Makefile @@ -406,7 +406,7 @@ uwsgi: collectstatic @if [ "$(VENV_BASE)" ]; then \ . $(VENV_BASE)/tower/bin/activate; \ fi; \ - uwsgi -b 32768 --socket :8050 --module=awx.wsgi:application --home=/venv/tower --chdir=/tower_devel/ --vacuum --processes=5 --harakiri=60 --master --no-orphans --py-autoreload 1 --max-requests=1000 --stats /tmp/stats.socket --master-fifo=/tmp/awxfifo + uwsgi -b 32768 --socket :8050 --module=awx.wsgi:application --home=/venv/tower --chdir=/tower_devel/ --vacuum --processes=5 --harakiri=60 --master --no-orphans --py-autoreload 1 --max-requests=1000 --stats /tmp/stats.socket --master-fifo=/tmp/awxfifo --lazy-apps daphne: @if [ "$(VENV_BASE)" ]; then \ diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 7ca90949a1..82a92f43fb 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -86,7 +86,8 @@ def celery_startup(conf=None, **kwargs): def uwsgi_reload(): - os.system("echo r > /tmp/awxfifo") + "Does chain reload of uWSGI" + os.system("echo c > /tmp/awxfifo") @task(queue='broadcast_all') From c6f3d498de863468644326a01e5fdeea8abfb4b2 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Fri, 9 Dec 2016 16:07:47 -0500 Subject: [PATCH 3/4] remove django configure_logging import --- awx/main/tasks.py | 1 - 1 file changed, 1 deletion(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 82a92f43fb..8e1c5b9731 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -43,7 +43,6 @@ from django.core.mail import send_mail from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ from django.core.cache import cache -from django.utils.log import configure_logging # AWX from awx.main.constants import CLOUD_PROVIDERS From 4cc1642ab3dffcfc2f177dd24ed751bfd4ac6c8d Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Mon, 12 Dec 2016 09:40:49 -0500 Subject: [PATCH 4/4] clarity edit of uWSGI chain reload task --- awx/main/tasks.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 8e1c5b9731..e0dcae0fca 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -85,8 +85,11 @@ def celery_startup(conf=None, **kwargs): def uwsgi_reload(): - "Does chain reload of uWSGI" - os.system("echo c > /tmp/awxfifo") + # http://uwsgi-docs.readthedocs.io/en/latest/MasterFIFO.html#available-commands + logger.warn('Initiating uWSGI chain reload of server') + TRIGGER_CHAIN_RELOAD = 'c' + with open('/tmp/awxfifo', 'w') as awxfifo: + awxfifo.write(TRIGGER_CHAIN_RELOAD) @task(queue='broadcast_all')