First function inserted

This commit is contained in:
2021-06-08 11:09:50 +00:00
parent ee3e9a075c
commit 69c666a68d

View File

@@ -15,51 +15,51 @@ service_exec=echo
TIMEOUT=5
RESTART=5
check_proxy_state() {
# Check services with running containers by roles
for CONTAINER in $(jq -r --arg ROLE $ROLE '.containers[] | select(.ROLES==$ROLE)' $PROXY_SERVICE_FILE | jq -r .NAME) ; do
CONTAINERS_BY_ROLE=$((CONTAINERS_BY_ROLE +1))
UP=$(docker ps | grep $CONTAINER | grep Up | wc -l)
RUNNING_CONTAINERS=$((RUNNING_CONTAINERS + UP))
done;
# The roles numbers and the running containers numbers are equal or greater than 2
if [[ "$RUNNING_CONTAINERS" == "$CONTAINERS_BY_ROLE" || "$RUNNING_CONTAINERS" == 2 ]] ; then
echo "Starting proxy restart process"
fi }
# Triggers by certificate or proxy config changes
unset IFS
inotifywait --exclude .swp -m -e CREATE,CLOSE_WRITE,CLOSE,DELETE -r $CERT_DIR $PROXY_CONFIG_DIR | \
inotifywait --exclude .sw -m -e CREATE,CLOSE_WRITE,CLOSE,DELETE -r $CERT_DIR $PROXY_CONFIG_DIR | \
while read dir op file
do
if [[ "${dir}" == "${CERT_DIR}" && "${op}" == "CLOSE_WRITE" ]]; then
DOMAIN=$(echo $dir|cut -d / -f3)
echo "New cert created: '$DOMAIN'"
elif [[ "${dir}" == "${PROXY_CONFIG_DIR}" && "${op}" == "CLOSE_WRITE" ]] || \
[[ "${dir}" == "${PROXY_CONFIG_DIR}" && "${op}" == "CREATE" ]] || \
[[ "${dir}" == "${PROXY_CONFIG_DIR}" && "${op}" == "DELETE" ]] ; then
echo "proxy config created, changed or deleted"
parent="/"$(echo $dir|cut -d / -f2)
if [[ "${parent}" == "${CERT_DIR}" && "${op}" == "CLOSE_WRITE,CLOSE" ]]; then
DOMAIN=$(echo $dir|cut -d / -f3);
echo "New cert created: '$DOMAIN'";
check_proxy_state;
elif [[ "${parent}" == "${PROXY_CONFIG_DIR}" && "${op}" == "CLOSE_WRITE,CLOSE" ]] || \
[[ "${parent}" == "${PROXY_CONFIG_DIR}" && "${op}" == "DELETE" ]] ; then
echo "proxy config created, changed or deleted";
check_proxy_state;
fi
done
# Check services with running containers by roles
#CONTAINER=$(jq -r --arg ROLE $ROLE '.containers[] | select(.ROLES==$ROLE)' $FILE | jq -r .NAME)
for CONTAINER in $(jq -r --arg ROLE $ROLE '.containers[] | select(.ROLES==$ROLE)' $PROXY_SERVICE_FILE | jq -r .NAME) ; do
#$service_exec $SERVICE_NAME.containers.$CONTAINER stop
#$service_exec $SERVICE_NAME.containers.$CONTAINER start
CONTAINERS_BY_ROLE=$((CONTAINERS_BY_ROLE +1))
UP=$(docker ps | grep $CONTAINER | grep Up | wc -l)
#if [[ $UP -eq 1 ]] ; then
# echo "FUT";
#fi
RUNNING_CONTAINERS=$((RUNNING_CONTAINERS + UP))
done;
# Running containers from existing roles
# echo $CONTAINERS_BY_ROLE;
# echo $RUNNING_CONTAINERS;
# The roles numbers and the running containers numbers are equal or greater than 2
if [[ "$RUNNING_CONTAINERS" == "$CONTAINERS_BY_ROLE" || "$RUNNING_CONTAINERS" == 2 ]] ; then
echo "Starting proxy restart process"
fi
#if [[ $UP -eq 1 ]] ; then
#fi
#$service_exec $SERVICE_NAME.containers.$CONTAINER stop
#$service_exec $SERVICE_NAME.containers.$CONTAINER start