mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
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:
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
set -e -o pipefail
|
set -e -o pipefail
|
||||||
|
|
||||||
TERMINATE_TIMEOUT=10
|
TERMINATE_TIMEOUT=9
|
||||||
|
readonly LOGS_DIR="/home/vcap/logs"
|
||||||
|
|
||||||
function check_params {
|
function check_params {
|
||||||
if [ -z "${NOTIFY_APP_NAME}" ]; then
|
if [ -z "${NOTIFY_APP_NAME}" ]; then
|
||||||
@@ -17,22 +18,22 @@ function check_params {
|
|||||||
|
|
||||||
function configure_aws_logs {
|
function configure_aws_logs {
|
||||||
# create files so that aws logs agent doesn't complain
|
# create files so that aws logs agent doesn't complain
|
||||||
touch /home/vcap/logs/gunicorn_error.log
|
touch ${LOGS_DIR}/gunicorn_error.log
|
||||||
touch /home/vcap/logs/app.log.json
|
touch ${LOGS_DIR}/app.log.json
|
||||||
|
|
||||||
aws configure set plugins.cwlogs cwlogs
|
aws configure set plugins.cwlogs cwlogs
|
||||||
|
|
||||||
cat > /home/vcap/app/awslogs.conf << EOF
|
cat > /home/vcap/app/awslogs.conf << EOF
|
||||||
[general]
|
[general]
|
||||||
state_file = /home/vcap/logs/awslogs-state
|
state_file = ${LOGS_DIR}/awslogs-state
|
||||||
|
|
||||||
[/home/vcap/logs/app.log]
|
[${LOGS_DIR}/app.log]
|
||||||
file = /home/vcap/logs/app.log.json
|
file = ${LOGS_DIR}/app.log.json
|
||||||
log_group_name = paas-${CW_APP_NAME}-application
|
log_group_name = paas-${CW_APP_NAME}-application
|
||||||
log_stream_name = {hostname}
|
log_stream_name = {hostname}
|
||||||
|
|
||||||
[/home/vcap/logs/gunicorn_error.log]
|
[${LOGS_DIR}/gunicorn_error.log]
|
||||||
file = /home/vcap/logs/gunicorn_error.log
|
file = ${LOGS_DIR}/gunicorn_error.log
|
||||||
log_group_name = paas-${CW_APP_NAME}-gunicorn
|
log_group_name = paas-${CW_APP_NAME}-gunicorn
|
||||||
log_stream_name = {hostname}
|
log_stream_name = {hostname}
|
||||||
EOF
|
EOF
|
||||||
@@ -41,12 +42,12 @@ EOF
|
|||||||
function on_exit {
|
function on_exit {
|
||||||
echo "Terminating application process with pid ${APP_PID}"
|
echo "Terminating application process with pid ${APP_PID}"
|
||||||
kill ${APP_PID} || true
|
kill ${APP_PID} || true
|
||||||
n=0
|
wait_time=0
|
||||||
while (kill -0 ${APP_PID} 2&>/dev/null); do
|
while (kill -0 ${APP_PID} 2&>/dev/null); do
|
||||||
echo "Application is still running.."
|
echo "Application is still running.."
|
||||||
sleep 1
|
sleep 1
|
||||||
let n=n+1
|
let wait_time=wait_time+1
|
||||||
if [ "$n" -ge "$TERMINATE_TIMEOUT" ]; then
|
if [ "$wait_time" -ge "$TERMINATE_TIMEOUT" ]; then
|
||||||
echo "Timeout reached, killing process with pid ${APP_PID}"
|
echo "Timeout reached, killing process with pid ${APP_PID}"
|
||||||
kill -9 ${APP_PID} || true
|
kill -9 ${APP_PID} || true
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
set -e -o pipefail
|
set -e -o pipefail
|
||||||
|
|
||||||
TERMINATE_TIMEOUT=9
|
TERMINATE_TIMEOUT=9
|
||||||
|
readonly LOGS_DIR="/home/vcap/logs"
|
||||||
|
|
||||||
function check_params {
|
function check_params {
|
||||||
if [ -z "${NOTIFY_APP_NAME}" ]; then
|
if [ -z "${NOTIFY_APP_NAME}" ]; then
|
||||||
@@ -17,22 +18,22 @@ function check_params {
|
|||||||
|
|
||||||
function configure_aws_logs {
|
function configure_aws_logs {
|
||||||
# create files so that aws logs agent doesn't complain
|
# create files so that aws logs agent doesn't complain
|
||||||
touch /home/vcap/logs/gunicorn_error.log
|
touch ${LOGS_DIR}/gunicorn_error.log
|
||||||
touch /home/vcap/logs/app.log.json
|
touch ${LOGS_DIR}/app.log.json
|
||||||
|
|
||||||
aws configure set plugins.cwlogs cwlogs
|
aws configure set plugins.cwlogs cwlogs
|
||||||
|
|
||||||
cat > /home/vcap/app/awslogs.conf << EOF
|
cat > /home/vcap/app/awslogs.conf << EOF
|
||||||
[general]
|
[general]
|
||||||
state_file = /home/vcap/logs/awslogs-state
|
state_file = ${LOGS_DIR}/awslogs-state
|
||||||
|
|
||||||
[/home/vcap/logs/app.log]
|
[${LOGS_DIR}/app.log]
|
||||||
file = /home/vcap/logs/app.log.json
|
file = ${LOGS_DIR}/app.log.json
|
||||||
log_group_name = paas-${CW_APP_NAME}-application
|
log_group_name = paas-${CW_APP_NAME}-application
|
||||||
log_stream_name = {hostname}
|
log_stream_name = {hostname}
|
||||||
|
|
||||||
[/home/vcap/logs/gunicorn_error.log]
|
[${LOGS_DIR}/gunicorn_error.log]
|
||||||
file = /home/vcap/logs/gunicorn_error.log
|
file = ${LOGS_DIR}/gunicorn_error.log
|
||||||
log_group_name = paas-${CW_APP_NAME}-gunicorn
|
log_group_name = paas-${CW_APP_NAME}-gunicorn
|
||||||
log_stream_name = {hostname}
|
log_stream_name = {hostname}
|
||||||
EOF
|
EOF
|
||||||
@@ -41,7 +42,7 @@ EOF
|
|||||||
# For every PID, check if it's still running
|
# For every PID, check if it's still running
|
||||||
# if it is, send the sigterm
|
# if it is, send the sigterm
|
||||||
function on_exit {
|
function on_exit {
|
||||||
n=0
|
wait_time=0
|
||||||
while true; do
|
while true; do
|
||||||
# refresh pids to account for the case that
|
# refresh pids to account for the case that
|
||||||
# some workers may have terminated but others not
|
# some workers may have terminated but others not
|
||||||
@@ -58,7 +59,7 @@ function on_exit {
|
|||||||
echo "Terminating celery processes with pids "${APP_PIDS}
|
echo "Terminating celery processes with pids "${APP_PIDS}
|
||||||
for APP_PID in ${APP_PIDS}; do
|
for APP_PID in ${APP_PIDS}; do
|
||||||
# if TERMINATE_TIMEOUT is reached, send SIGKILL
|
# if TERMINATE_TIMEOUT is reached, send SIGKILL
|
||||||
if [[ "$n" -ge "$TERMINATE_TIMEOUT" ]]; then
|
if [[ "$wait_time" -ge "$TERMINATE_TIMEOUT" ]]; then
|
||||||
echo "Timeout reached, killing process with pid ${APP_PID}"
|
echo "Timeout reached, killing process with pid ${APP_PID}"
|
||||||
kill -9 ${APP_PID} || true
|
kill -9 ${APP_PID} || true
|
||||||
continue
|
continue
|
||||||
@@ -71,7 +72,7 @@ function on_exit {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
let n=n+1
|
let wait_time=wait_time+1
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user