From 01611c1936073cda3a817cfb7c99ba2120efa36b Mon Sep 17 00:00:00 2001 From: Athanasios Voutsadakis Date: Fri, 22 Sep 2017 11:28:55 +0100 Subject: [PATCH 1/4] Configure gunicorn error log file --- manifest-api-base.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest-api-base.yml b/manifest-api-base.yml index 19c198d21..b761afb4d 100644 --- a/manifest-api-base.yml +++ b/manifest-api-base.yml @@ -1,7 +1,7 @@ --- buildpack: python_buildpack -command: scripts/run_app_paas.sh gunicorn -w 5 -b 0.0.0.0:$PORT wsgi +command: scripts/run_app_paas.sh gunicorn --error-logfile /home/vcap/logs/gunicorn_error.log -w 5 -b 0.0.0.0:$PORT wsgi services: - notify-aws - notify-config From 646290e2c4d0fb7d9ed59bec83e7d57046ece503 Mon Sep 17 00:00:00 2001 From: Athanasios Voutsadakis Date: Fri, 22 Sep 2017 15:03:45 +0100 Subject: [PATCH 2/4] Implement worker_abort server hook Also update the manifest command to pass the config file in as a parameter and modify the logs agent to start shipping the error log to cloudwatch --- gunicorn_config.py | 5 +++++ manifest-api-base.yml | 2 +- scripts/run_app_paas.sh | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 gunicorn_config.py diff --git a/gunicorn_config.py b/gunicorn_config.py new file mode 100644 index 000000000..079e35f64 --- /dev/null +++ b/gunicorn_config.py @@ -0,0 +1,5 @@ +def worker_abort(worker): + worker.log.info("worker received ABORT") + import sys, traceback + for threadId, stack in sys._current_frames().items(): + worker.log.info(''.join(traceback.format_stack(stack))) diff --git a/manifest-api-base.yml b/manifest-api-base.yml index b761afb4d..28cf8a8cd 100644 --- a/manifest-api-base.yml +++ b/manifest-api-base.yml @@ -1,7 +1,7 @@ --- buildpack: python_buildpack -command: scripts/run_app_paas.sh gunicorn --error-logfile /home/vcap/logs/gunicorn_error.log -w 5 -b 0.0.0.0:$PORT wsgi +command: scripts/run_app_paas.sh gunicorn -c /home/vcap/app/gunicorn_config.py --error-logfile /home/vcap/logs/gunicorn_error.log -w 5 -b 0.0.0.0:$PORT wsgi services: - notify-aws - notify-config diff --git a/scripts/run_app_paas.sh b/scripts/run_app_paas.sh index 90205fd73..2813f851f 100755 --- a/scripts/run_app_paas.sh +++ b/scripts/run_app_paas.sh @@ -29,6 +29,11 @@ state_file = /home/vcap/logs/awslogs-state file = /home/vcap/logs/app.log.json log_group_name = paas-${CW_APP_NAME}-application log_stream_name = {hostname} + +[/home/vcap/logs/gunicorn_error.log] +file = /home/vcap/logs/gunicorn_error.log +log_group_name = paas-${CW_APP_NAME}-gunicorn +log_stream_name = {hostname} EOF } From 291071273e892712a565bfa48f721904094c3c39 Mon Sep 17 00:00:00 2001 From: Athanasios Voutsadakis Date: Fri, 22 Sep 2017 15:34:43 +0100 Subject: [PATCH 3/4] Fix PEP8 --- gunicorn_config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gunicorn_config.py b/gunicorn_config.py index 079e35f64..86e2567d5 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -1,5 +1,8 @@ +import sys +import traceback + + def worker_abort(worker): worker.log.info("worker received ABORT") - import sys, traceback for threadId, stack in sys._current_frames().items(): worker.log.info(''.join(traceback.format_stack(stack))) From f32a243e471e794bfe8289fc297aac966c634196 Mon Sep 17 00:00:00 2001 From: Athanasios Voutsadakis Date: Mon, 25 Sep 2017 16:24:35 +0100 Subject: [PATCH 4/4] Change .info to .error --- gunicorn_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gunicorn_config.py b/gunicorn_config.py index 86e2567d5..11993ab78 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -5,4 +5,4 @@ import traceback def worker_abort(worker): worker.log.info("worker received ABORT") for threadId, stack in sys._current_frames().items(): - worker.log.info(''.join(traceback.format_stack(stack))) + worker.log.error(''.join(traceback.format_stack(stack)))