From 66dc81319274c6dc139b47732bdbd326db4f60b5 Mon Sep 17 00:00:00 2001 From: Mira Kuntz Date: Wed, 27 Mar 2024 11:41:59 +0100 Subject: [PATCH] added handling for 0 and 1 handlers --- parts/24-gunicorn.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/parts/24-gunicorn.sh b/parts/24-gunicorn.sh index c5a85c6..003aa1d 100644 --- a/parts/24-gunicorn.sh +++ b/parts/24-gunicorn.sh @@ -18,23 +18,26 @@ gunicorn_handler-restart() { readarray -t gunicorns < <(systemctl list-units --state=running | grep galaxy-gunicorn | cut -d '@' -f2 | cut -d '.' -f1) # Calculate batch size - # batch_size=$(( (${#gunicorns[@]} + 1) / 2 )) - batch_size=$(( (${#gunicorns[@]} - 1) / 2 + 1)) - + batch_size=$(( (${#gunicorns[@]} + 1) / 2 )) + if ((${#gunicorns[@]} < 2)); then + echo "You have too few Gunicorn handlers to restart in batch mode. Please restart manually." + exit 1 + fi # Construct service name ranges for each batch batch1="" batch2="" - for ((i = 0; i < ${#gunicorns[@]} - 1; i++)); do + for ((i = 0; i < ${#gunicorns[@]}; i++)); do if ((i < batch_size)); then batch1+="galaxy-gunicorn@${gunicorns[i]}.service " else batch2+="galaxy-gunicorn@${gunicorns[i]}.service " fi done + echo "Found handlers: $batch1 and $batch2" # Restart each batch if systemctl status $batch1 | grep "GET" | grep "200" >/dev/null then - echo "First restarting: $batch2" + echo "First restarting: $batch2" systemctl restart $batch2 while true do