Major changes: scheduler do action when

- in case of no running proxies found
- in case of only one running proxy found
This commit is contained in:
2021-06-12 22:03:55 +00:00
parent 96513fecd1
commit 34ec335389

View File

@@ -1,6 +1,6 @@
#!/bin/sh
service_exec=echo
service_exec="docker run --rm -v /etc/user/config/services/:/services/:ro -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker:ro registry.format.hu/setup /scripts/service-exec"
# Initial parameters
DATE=`date +%F-%H-%M-%S`
@@ -16,6 +16,49 @@ service_exec=echo
ROLE="backend-proxy"
SERVICE_NAME="public-proxy"
do_proxy_restart() {
for proxies in $CONTAINER_NAMES ; do
docker stop $proxies;
sleep $TIMEOUT;
#$service_exec $SERVICE_NAME.containers.$proxies start
if docker ps | grep $proxies ; then
echo "$proxies restarted successful";
else
RESTART_COUNTER=0
PROXY_NAME=$proxies
for retries in $(seq 0 $RESTART); do
RESTART_COUNTER=$((RESTART_COUNTER +1))
echo "Retried number is: "$retries;
echo "restart_value is: "$RESTART;
echo "restart counter is: "$RESTART_COUNTER;
echo "proxy name: "$PROXY_NAME;
if [[ $RESTART -le $retries ]] ; then
echo "Proxy "$PROXY_NAME" restarting in progress";
#$service_exec $SERVICE_NAME.containers.$PROXY_NAME start
if docker ps | grep $PROXY_NAME ; then
echo "$PROXY_NAME restarted successful";
else
echo "Restarting number is only: "$retries" so try again"
sleep 3;
#sleep $TIMEOUT;
fi
else
echo "Reached retrying limit: "$RESTART" ,giving up, starting recocer previous state"
recover_process;
fi
done
fi
done
}
check_domain() { echo "Checking $DOMAIN name"
}
recover_process() { echo "Recovering previous state"
}
send_error_msg () { echo "Sending error messages"
}
check_proxy_state() {
# Set restart counter to zero
@@ -32,6 +75,8 @@ for CONTAINER in $(jq -r --arg ROLE $ROLE '.containers[] | select(.ROLES==$ROLE)
UP=$(docker ps | grep $CONTAINER | grep Up | wc -l)
RUNNING_CONTAINERS=$((RUNNING_CONTAINERS + UP))
CONTAINERS=$CONTAINERS" "$CONTAINER;
if [[ "$UP" != 0 ]]; then
CONTAINER_NAMES=$CONTAINER_NAMES" "$CONTAINER;
fi;
@@ -40,9 +85,41 @@ done;
# The roles numbers and the running containers numbers are equal or greater than 2
if [[ "$RUNNING_CONTAINERS" == "$CONTAINERS_BY_ROLE" || "$RUNNING_CONTAINERS" -ge 2 ]] ; then
echo "Starting proxy restart process";
echo $CONTAINER_NAMES;
do_proxy_restart ;
# In case of no running proxies found, try to start the service
elif [[ "$RUNNING_CONTAINERS" -eq 0 ]] ; then
echo "No running proxies found, starting all";
for proxies in $CONTAINERS ; do
$service_exec $SERVICE_NAME.containers.$proxies start;
if docker ps | grep $proxies ; then
echo "$proxies started successful";
else
echo "$proxies starting was unsuccesful"
fi
done
# In case of only one running proxy found, try to start the others of the service
elif [[ "$RUNNING_CONTAINERS" -eq 1 ]] ; then
echo "Only one running proxy found, starting all of the others";
for proxies in $CONTAINERS ; do
if [[ $proxies != $CONTAINER_NAMES ]] ; then
echo "No running containers: "$proxies" found.";
$service_exec $SERVICE_NAME.containers.$proxies start;
if docker ps | grep $proxies ; then
echo "$proxies started successful";
else
echo "$proxies starting was unsuccesful";
fi
# At last need to restart the only one running proxy when the others started successful.
else
ONLY_RUNNING_PROXY_NAME=$proxies;
fi
done
echo "Only running proxy name="$ONLY_RUNNING_PROXY_NAME;
else
sleep $TIMEOUT;
RESTART_COUNTER=$((RESTART_COUNTER +1))
@@ -64,17 +141,6 @@ fi
}
do_proxy_restart() { echo "Proxy restarts"
}
check_domain() { echo "Checking $DOMAIN name"
}
recover_process() { echo "Recovering previous state"
}
send_error_msg () { echo "Sending error messages"
}
# Triggers by certificate or proxy config changes