create json files
This commit is contained in:
@@ -8,6 +8,7 @@ USER_INIT_PATH=$USER_INIT_PATH
|
|||||||
FRAMEWORK_SCHEDULER_IMAGE=${FRAMEWORK_SCHEDULER_IMAGE:-framework-scheduler}
|
FRAMEWORK_SCHEDULER_IMAGE=${FRAMEWORK_SCHEDULER_IMAGE:-framework-scheduler}
|
||||||
FRAMEWORK_SCHEDULER_NAME=${FRAMEWORK_SCHEDULER_NAME:-framework-scheduler}
|
FRAMEWORK_SCHEDULER_NAME=${FRAMEWORK_SCHEDULER_NAME:-framework-scheduler}
|
||||||
FRAMEWORK_SCHEDULER_NETWORK=${FRAMEWORK_SCHEDULER_NETWORK:-framework-network}
|
FRAMEWORK_SCHEDULER_NETWORK=${FRAMEWORK_SCHEDULER_NETWORK:-framework-network}
|
||||||
|
FRAMEWORK_SCHEDULER_NETWORK_SUBNET=${FRAMEWORK_SCHEDULER_NETWORK_SUBNET:-"172.19.255.0/24"}
|
||||||
FRAMEWORK_SCHEDULER_VERSION=${FRAMEWORK_SCHEDULER_VERSION:-latest}
|
FRAMEWORK_SCHEDULER_VERSION=${FRAMEWORK_SCHEDULER_VERSION:-latest}
|
||||||
|
|
||||||
WEB_SERVER=${WEB_SERVER:-webserver}
|
WEB_SERVER=${WEB_SERVER:-webserver}
|
||||||
@@ -80,10 +81,13 @@ check_volumes(){
|
|||||||
/usr/bin/docker volume create USER_CONFIG;
|
/usr/bin/docker volume create USER_CONFIG;
|
||||||
RET=0;
|
RET=0;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
echo $RET;
|
||||||
}
|
}
|
||||||
|
|
||||||
check_dirs_and_files(){
|
check_dirs_and_files(){
|
||||||
|
|
||||||
|
RET=0;
|
||||||
if [ ! -d "/etc/user/config/services/" ]; then
|
if [ ! -d "/etc/user/config/services/" ]; then
|
||||||
mkdir /etc/user/config/services/
|
mkdir /etc/user/config/services/
|
||||||
fi;
|
fi;
|
||||||
@@ -101,55 +105,67 @@ check_dirs_and_files(){
|
|||||||
|
|
||||||
check_subnets(){
|
check_subnets(){
|
||||||
|
|
||||||
|
RET=1;
|
||||||
SUBNETS=$(for ALL in $(/usr/bin/docker network ls | grep bridge | awk '{print $1}') ; do /usr/bin/docker network inspect $ALL --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' ; done)
|
SUBNETS=$(for ALL in $(/usr/bin/docker network ls | grep bridge | awk '{print $1}') ; do /usr/bin/docker network inspect $ALL --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}' ; done)
|
||||||
|
|
||||||
RES=$(echo "$SUBNETS" | grep "172.19.");
|
RES=$(echo "$SUBNETS" | grep "172.19.");
|
||||||
if [ "$RES" != "" ]; then
|
if [ "$RES" != "" ]; then
|
||||||
for R in $RES ; do
|
for R in $RES ; do
|
||||||
NUMBER=$(echo $R | cut -d '.' -f3);
|
NUMBER=$(echo $R | cut -d '.' -f3);
|
||||||
if [[ $NUMBER > 0 && $NUMBER < 255 ]]; then
|
if [[ $NUMBER -ge 0 && $NUMBER < 255 ]]; then
|
||||||
echo $NUMBER;
|
RET=0
|
||||||
echo "TODO"
|
|
||||||
fi;
|
fi;
|
||||||
done;
|
done;
|
||||||
fi;
|
fi;
|
||||||
|
echo $RET;
|
||||||
}
|
}
|
||||||
|
|
||||||
check_framework_scheduler_status(){
|
check_framework_scheduler_status(){
|
||||||
|
|
||||||
ACTUAL_FRAMEWORK_SCHEDULER_NAME=$1;
|
ACTUAL_FRAMEWORK_SCHEDULER_NAME=$1;
|
||||||
|
|
||||||
if "$ACTUAL_FRAMEWORK_SCHEDULER_NAME" == "$FRAMEWORK_SCHEDULER_NAME"; then
|
RET=1;
|
||||||
echo "Scheduler name not correct, not needed to restart is with the correct name";
|
if "$ACTUAL_FRAMEWORK_SCHEDULER_NAME" != "$FRAMEWORK_SCHEDULER_NAME"; then
|
||||||
else
|
RET=0;
|
||||||
FRAMEWORK_NAME=0;
|
else
|
||||||
fi
|
desired_subnet=$FRAMEWORK_SCHEDULER_NETWORK_SUBNET
|
||||||
|
existing_subnets=$(/usr/bin/docker network inspect $(/usr/bin/docker network ls -q) --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}')
|
||||||
|
|
||||||
|
# Check if the desired subnet is in the list of existing subnets
|
||||||
|
if echo "$existing_subnets" | grep -q "$desired_subnet"; then
|
||||||
|
if [ "$(/usr/bin/docker network inspect $FRAMEWORK_SCHEDULER_NETWORK --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}')" != "$FRAMEWORK_NETWORK_SUBNET" ]; then
|
||||||
|
RET=0;
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
RET=0;
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$(/usr/bin/docker network inspect $FRAMEWORK_SCHEDULER_NETWORK --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}')" == "$FRAMEWORK_NETWORK_SUBNET" ]; then
|
|
||||||
echo "Network $FRAMEWORK_SCHEDULER_NETWORK is available with the correct subnet, not needed to restart the scheduler"
|
|
||||||
else
|
|
||||||
check_framework_subnet_availabity
|
|
||||||
FRAMEWORK_SUBNET=0;
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
#echo '{"FRAMEWORK_NAME": "$FRAMEWORK_NAME", "FRAMEWORK_NETWORK": "$FRAMEWORK_NETWORK"}'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_system_json() {
|
||||||
|
{
|
||||||
|
echo '
|
||||||
|
{
|
||||||
|
"NETWORK": {
|
||||||
|
"IP_POOL_START": "172.19.0.0",
|
||||||
|
"IP_POOL_END": "172.19.254.0",
|
||||||
|
"IP_SUBNET": "24"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
';
|
||||||
|
} > /etc/user/config/system.json
|
||||||
|
}
|
||||||
|
|
||||||
check_framework_subnet_availabity() {
|
create_user_json() {
|
||||||
|
touch /etc/user/config/user.json
|
||||||
# Define the subnet you want to check
|
}
|
||||||
desired_subnet=$FRAMEWORK_NETWORK_SUBNET
|
|
||||||
existing_subnets=$(/usr/bin/docker network inspect $(/usr/bin/docker network ls -q) --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}')
|
|
||||||
|
|
||||||
# Check if the desired subnet is in the list of existing subnets
|
create_framework_json() {
|
||||||
if echo "$existing_subnets" | grep -q "$desired_subnet"; then
|
{
|
||||||
echo "Subnet $desired_subnet is not available for creation. Need to find another network"
|
echo '
|
||||||
else
|
';
|
||||||
echo "Subnet $desired_subnet is available for creation."
|
} > /etc/user/config/services/service-framework.json
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_redis_availability() {
|
check_redis_availability() {
|
||||||
@@ -195,15 +211,28 @@ start_webserver () {
|
|||||||
## PORTS VARIABLES
|
## PORTS VARIABLES
|
||||||
### RESTART SCHEDULER IF NEEDED
|
### RESTART SCHEDULER IF NEEDED
|
||||||
|
|
||||||
|
SN=$(check_subnets)
|
||||||
|
if [ "$SN" != "1"]; then
|
||||||
|
echo "Desired network subnet not available";
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
STATUS=$(check_framework_scheduler_status $HOSTNAME)
|
||||||
|
if [ "$STATUS" != "1" ]; then
|
||||||
|
/usr/bin/docker network create $FRAMEWORK_SCHEDULER_NETWORK --subnet $FRAMEWORK_SCHEDULER_NETWORK_SUBNET;
|
||||||
|
fi;
|
||||||
|
|
||||||
VOL=$(check_volumes)
|
VOL=$(check_volumes)
|
||||||
if [ "$VOL" != "1" ]; then
|
if [ "$VOL" != "1" ]; then
|
||||||
/usr/bin/docker run -d --rm -v /var/run/docker.sock:/var/run/docker.sock --name $FRAMEWORK_SCHEDULER_NAME $DOCKER_REGISTRY_URL/$FRAMEWORK_SCHEDULER_IMAGE:$FRAMEWORK_SCHEDULER_VERSION
|
/usr/bin/docker run -d -v /var/run/docker.sock:/var/run/docker.sock --name $FRAMEWORK_SCHEDULER_NAME --network $FRAMEWORK_SCHEDULER_NETWORK_SUBNET $DOCKER_REGISTRY_URL/$FRAMEWORK_SCHEDULER_IMAGE:$FRAMEWORK_SCHEDULER_VERSION
|
||||||
/usr/bin/docker stop $HOSTNAME;
|
/usr/bin/docker stop $HOSTNAME;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
exit;
|
DF=$(check_dirs_and_files);
|
||||||
|
if [ "$DF" != "1" ]; then
|
||||||
check_framework_scheduler_status $HOSTNAME
|
create_system_json;
|
||||||
|
create_user_json;
|
||||||
|
create_framework_json;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
|
||||||
# REDIS_SERVER EXISTENCE
|
# REDIS_SERVER EXISTENCE
|
||||||
|
Reference in New Issue
Block a user