Address PR comments

Make timeout 9s on both files
Use more descriptive variable name
Declare the logs dir as a constant
This commit is contained in:
Athanasios Voutsadakis
2018-03-06 15:58:33 +00:00
parent 3045f6233b
commit d365921093
2 changed files with 23 additions and 21 deletions

View File

@@ -2,7 +2,8 @@
set -e -o pipefail
TERMINATE_TIMEOUT=10
TERMINATE_TIMEOUT=9
readonly LOGS_DIR="/home/vcap/logs"
function check_params {
if [ -z "${NOTIFY_APP_NAME}" ]; then
@@ -17,22 +18,22 @@ function check_params {
function configure_aws_logs {
# create files so that aws logs agent doesn't complain
touch /home/vcap/logs/gunicorn_error.log
touch /home/vcap/logs/app.log.json
touch ${LOGS_DIR}/gunicorn_error.log
touch ${LOGS_DIR}/app.log.json
aws configure set plugins.cwlogs cwlogs
cat > /home/vcap/app/awslogs.conf << EOF
[general]
state_file = /home/vcap/logs/awslogs-state
state_file = ${LOGS_DIR}/awslogs-state
[/home/vcap/logs/app.log]
file = /home/vcap/logs/app.log.json
[${LOGS_DIR}/app.log]
file = ${LOGS_DIR}/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
[${LOGS_DIR}/gunicorn_error.log]
file = ${LOGS_DIR}/gunicorn_error.log
log_group_name = paas-${CW_APP_NAME}-gunicorn
log_stream_name = {hostname}
EOF
@@ -41,12 +42,12 @@ EOF
function on_exit {
echo "Terminating application process with pid ${APP_PID}"
kill ${APP_PID} || true
n=0
wait_time=0
while (kill -0 ${APP_PID} 2&>/dev/null); do
echo "Application is still running.."
sleep 1
let n=n+1
if [ "$n" -ge "$TERMINATE_TIMEOUT" ]; then
let wait_time=wait_time+1
if [ "$wait_time" -ge "$TERMINATE_TIMEOUT" ]; then
echo "Timeout reached, killing process with pid ${APP_PID}"
kill -9 ${APP_PID} || true
break