2024-07-04 12:42:13 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
#1 : action = default up
|
|
|
|
|
#2 : service = optionnel
|
|
|
|
|
|
2024-07-24 16:11:40 +02:00
|
|
|
|
# Include bibliotheque de fonction
|
|
|
|
|
. ./misc/tools/e-ihm.sh
|
|
|
|
|
|
|
|
|
|
# Start script
|
|
|
|
|
BigTitle "NINE"
|
2024-07-04 12:42:13 +02:00
|
|
|
|
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
#== STOP ===================================================================================================================================
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
#1 = service to stop if null all service
|
|
|
|
|
#2 = stopper par destroyall
|
|
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
|
if [[ "$2" != 1 ]]; then Title "STOP"; fi
|
|
|
|
|
|
2024-07-24 16:11:40 +02:00
|
|
|
|
echo "docker-compose stop $1"
|
2024-07-05 23:01:17 +02:00
|
|
|
|
docker-compose stop $1
|
2024-07-24 16:11:40 +02:00
|
|
|
|
|
|
|
|
|
if [[ "$2" != 1 ]]; then echo; fi
|
2024-07-28 16:57:55 +02:00
|
|
|
|
|
|
|
|
|
if [[ "$2" != 1 ]]; then Title "REMOVE"; fi
|
|
|
|
|
|
|
|
|
|
if [[ "$1" != "" ]]; then
|
|
|
|
|
docker-compose rm -s -v -f "${1}"
|
|
|
|
|
else
|
|
|
|
|
for key in $(for k in "${!services[@]}"; do echo "$k:${services[$k]}"; done | sort -t: -k2,2 | cut -d: -f1); do
|
|
|
|
|
docker-compose rm -s -v -f "${key}"
|
|
|
|
|
done;
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ "$2" != 1 ]]; then echo; fi
|
2024-07-04 12:42:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#===========================================================================================================================================
|
2024-07-27 10:19:39 +02:00
|
|
|
|
#== WAIT_FOR_CONTAINER =====================================================================================================================
|
2024-07-04 12:42:13 +02:00
|
|
|
|
#===========================================================================================================================================
|
2024-07-27 10:19:39 +02:00
|
|
|
|
#1 = service to wait
|
2024-07-04 12:42:13 +02:00
|
|
|
|
|
|
|
|
|
wait_for_container() {
|
|
|
|
|
container_id="nine-$1"
|
2024-07-05 23:01:17 +02:00
|
|
|
|
container_name="$(docker inspect "${container_id}" --format '{{ .Name }}')"
|
2024-07-04 12:42:13 +02:00
|
|
|
|
waiting_done="false"
|
|
|
|
|
|
|
|
|
|
while [[ "${waiting_done}" != "true" ]]; do
|
2024-07-05 23:01:17 +02:00
|
|
|
|
container_state="$(docker inspect "${container_id}" --format '{{ .State.Status }}')"
|
2024-07-04 12:42:13 +02:00
|
|
|
|
if [[ "${container_state}" == "running" ]]; then
|
2024-07-05 23:01:17 +02:00
|
|
|
|
health_status="$(docker inspect "${container_id}" --format '{{ .State.Health.Status }}')"
|
2024-07-04 12:42:13 +02:00
|
|
|
|
if [[ ${health_status} == "healthy" ]]; then
|
|
|
|
|
waiting_done="true"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
waiting_done="true"
|
|
|
|
|
fi
|
|
|
|
|
sleep 1;
|
|
|
|
|
done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
#== UP =====================================================================================================================================
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
#1 = service to up if null all service
|
|
|
|
|
|
|
|
|
|
up(){
|
|
|
|
|
# Stop du ou des services
|
|
|
|
|
stop $1
|
|
|
|
|
|
|
|
|
|
# SERVICES
|
|
|
|
|
if [[ -z "$1" ]]
|
|
|
|
|
then
|
2024-07-24 16:11:40 +02:00
|
|
|
|
# Pour chaque répertoire service on execute sa fonction up
|
|
|
|
|
for key in $(for k in "${!services[@]}"; do echo "$k:${services[$k]}"; done | sort -t: -k2,2 | cut -d: -f1); do
|
|
|
|
|
up${key}
|
|
|
|
|
done
|
2024-07-04 12:42:13 +02:00
|
|
|
|
else
|
|
|
|
|
up${1}
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-26 22:34:20 +02:00
|
|
|
|
upservice(){
|
|
|
|
|
docker-compose up -d --remove-orphans $1
|
|
|
|
|
if [[ $2 == "wait" ]]
|
|
|
|
|
then
|
|
|
|
|
wait_for_container $1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 12:42:13 +02:00
|
|
|
|
#===========================================================================================================================================
|
2024-07-26 22:34:20 +02:00
|
|
|
|
#== DESTROYALL =============================================================================================================================
|
2024-07-04 12:42:13 +02:00
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
|
|
|
|
|
destroyall(){
|
|
|
|
|
Question_ouinon "Souhaitez-vous supprimer l'ensemble des containers : Attention cela supprimera vraiment tout ?"
|
|
|
|
|
if [[ "$?" = 0 ]]
|
|
|
|
|
then
|
2024-07-24 16:11:40 +02:00
|
|
|
|
# Pour chaque répertoire service on execute sa fonction destroy
|
|
|
|
|
# On part du dernier service vers le premiser
|
|
|
|
|
for key in $(for k in "${!services[@]}"; do echo "$k:${services[$k]}"; done | sort -t: -k2,2r | cut -d: -f1); do
|
|
|
|
|
destroy${key} 1
|
|
|
|
|
done
|
2024-07-04 12:42:13 +02:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-28 17:25:52 +02:00
|
|
|
|
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
#== PULL ===================================================================================================================================
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
|
|
|
|
|
pull(){
|
|
|
|
|
if [[ "$1" == "" ]]
|
|
|
|
|
then
|
|
|
|
|
Question_ouinon "Souhaitez-vous mettre à jour les images ?"
|
|
|
|
|
else
|
|
|
|
|
Question_ouinon "Souhaitez-vous mettre à jour l'images du service $1 ?"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ "$?" = 0 ]]
|
|
|
|
|
then
|
|
|
|
|
stop $1
|
|
|
|
|
docker-compose pull $1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-27 10:19:39 +02:00
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
#== ENV ====================================================================================================================================
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
# Construction des environnements mergés par service
|
|
|
|
|
|
|
|
|
|
env(){
|
|
|
|
|
for dir in $(ls -d "services"/[0-9][0-9]-* | sort); do
|
2024-10-21 17:00:05 +02:00
|
|
|
|
mergeenv $dir/env/.env.merge env/.env.merge $dir/env/.env $dir/env/.env.local
|
|
|
|
|
#misc/tools/mergeenv.sh $dir
|
2024-07-27 10:19:39 +02:00
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
#== DOCKERCOMPOSE ====================================================================================================================================
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
# Construction du dockercompose
|
|
|
|
|
|
|
|
|
|
dockercompose() {
|
|
|
|
|
|
2024-09-18 15:30:17 +02:00
|
|
|
|
echo "services:" > services.yml
|
|
|
|
|
echo "secrets:" > secrets.yml
|
|
|
|
|
echo "networks:" > networks.yml
|
|
|
|
|
echo " nine-network:" >> networks.yml
|
|
|
|
|
echo " name: nine-network" >> networks.yml
|
2024-07-27 10:19:39 +02:00
|
|
|
|
for dir in $(ls -d "services"/[0-9][0-9]-* | sort); do
|
|
|
|
|
# Construction du docker-compose
|
|
|
|
|
if [ -f "$dir/dockercompose/dockercompose.yml" ]; then
|
2024-09-18 15:30:17 +02:00
|
|
|
|
unset section
|
|
|
|
|
while read; do
|
|
|
|
|
case $REPLY in
|
|
|
|
|
"services:")
|
|
|
|
|
section=${REPLY%:}
|
|
|
|
|
;;
|
|
|
|
|
"secrets:")
|
|
|
|
|
section=${REPLY%:}
|
|
|
|
|
;;
|
|
|
|
|
"networks:")
|
|
|
|
|
section=${REPLY%:}
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
if [ -n "$section" ]; then
|
|
|
|
|
echo "$REPLY" >> ${section}.yml
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
esac
|
|
|
|
|
done < "$dir/dockercompose/dockercompose.yml"
|
2024-07-27 10:19:39 +02:00
|
|
|
|
fi
|
|
|
|
|
done
|
2024-09-18 15:30:17 +02:00
|
|
|
|
cat services.yml secrets.yml networks.yml > docker-compose.yml
|
|
|
|
|
rm -f services.yml secrets.yml networks.yml
|
2024-07-27 10:19:39 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
#== APACHE =================================================================================================================================
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
# Construction conf apache
|
|
|
|
|
|
|
|
|
|
apache(){
|
|
|
|
|
for dir in $(ls -d "services"/[0-9][0-9]-* | sort); do
|
|
|
|
|
keyservice="${dir##*-}"
|
|
|
|
|
valueservice="${dir##*/}"
|
|
|
|
|
|
|
|
|
|
mkdir -p services/10-nineapache/volume/apache
|
|
|
|
|
if [ -f "$dir/apache/apache.conf" ]; then
|
|
|
|
|
cp "$dir/apache/apache.conf" services/10-nineapache/volume/apache/$valueservice.conf
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
#== TEMPLATE================================================================================================================================
|
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
# Templatisation
|
|
|
|
|
|
|
|
|
|
template() {
|
|
|
|
|
for dir in $(ls -d "services"/[0-9][0-9]-* | sort); do
|
|
|
|
|
misc/tools/dicos.sh $dir
|
|
|
|
|
done
|
|
|
|
|
}
|
2024-07-04 12:42:13 +02:00
|
|
|
|
|
|
|
|
|
#===========================================================================================================================================
|
2024-07-27 11:01:26 +02:00
|
|
|
|
#== SERVICES ===============================================================================================================================
|
2024-07-04 12:42:13 +02:00
|
|
|
|
#===========================================================================================================================================
|
2024-07-27 11:01:26 +02:00
|
|
|
|
# Liste des services
|
|
|
|
|
|
|
|
|
|
services() {
|
|
|
|
|
Title "SERVICES"
|
2024-07-04 12:42:13 +02:00
|
|
|
|
|
2024-07-27 11:01:26 +02:00
|
|
|
|
for dir in $(ls -d "services"/[0-9][0-9]-* | sort); do
|
|
|
|
|
keyservice="${dir##*-}"
|
|
|
|
|
valueservice="${dir##*/}"
|
|
|
|
|
Echo $keyservice
|
|
|
|
|
done
|
|
|
|
|
}
|
2024-07-27 10:19:39 +02:00
|
|
|
|
|
2024-07-27 11:01:26 +02:00
|
|
|
|
#===========================================================================================================================================
|
|
|
|
|
#== MAIN ===================================================================================================================================
|
|
|
|
|
#===========================================================================================================================================
|
2024-07-27 10:19:39 +02:00
|
|
|
|
|
|
|
|
|
# Include variable d'environnement global
|
2024-10-21 17:00:05 +02:00
|
|
|
|
mergeenv env/.env.merge env/.env env/.env.local
|
|
|
|
|
#misc/tools/mergeenv.sh
|
2024-07-27 10:19:39 +02:00
|
|
|
|
. env/.env.merge
|
|
|
|
|
# Include service
|
|
|
|
|
declare -A services
|
|
|
|
|
for dir in $(ls -d "services"/[0-9][0-9]-* | sort); do
|
|
|
|
|
keyservice="${dir##*-}"
|
|
|
|
|
valueservice="${dir##*/}"
|
|
|
|
|
|
|
|
|
|
# Include bibliotheque de fonction
|
|
|
|
|
if [ -f "$dir/misc/nine.sh" ]; then
|
|
|
|
|
. $dir/misc/nine.sh
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Include variable d'environnement global
|
|
|
|
|
if [ -f "$dir/env/.env" ]; then
|
|
|
|
|
. $dir/env/.env
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Include variable d'environnement local
|
|
|
|
|
if [ -f "$dir/env/.env.local" ]; then
|
|
|
|
|
. $dir/env/.env.local
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Sauvegarder le service
|
|
|
|
|
services["$keyservice"]="$valueservice"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Construction des environnements mergés par service
|
|
|
|
|
env
|
|
|
|
|
|
|
|
|
|
# Construction docker_compose
|
|
|
|
|
dockercompose
|
|
|
|
|
|
|
|
|
|
# Construction de la configuration apache
|
|
|
|
|
apache
|
|
|
|
|
|
|
|
|
|
# Templetisation
|
|
|
|
|
template
|
|
|
|
|
|
|
|
|
|
# Execution de la commande
|
2024-07-04 12:42:13 +02:00
|
|
|
|
if [[ $1 == "up" || $1 == "" ]]
|
|
|
|
|
then
|
|
|
|
|
up $2
|
2024-07-24 16:11:40 +02:00
|
|
|
|
elif [[ $1 == "uplogs" || $1 == "" ]]
|
|
|
|
|
then
|
|
|
|
|
up $2
|
|
|
|
|
docker-compose logs -f $2
|
2024-07-04 12:42:13 +02:00
|
|
|
|
elif [[ $1 == "stop" ]]
|
|
|
|
|
then
|
|
|
|
|
stop $2
|
|
|
|
|
elif [[ $1 == "bash" ]]
|
|
|
|
|
then
|
|
|
|
|
if [[ -z $2 ]]
|
|
|
|
|
then
|
|
|
|
|
EchoRouge "Vous devez precisez un service"
|
|
|
|
|
EchoRouge "nine.sh bash monservice"
|
|
|
|
|
else
|
2024-07-05 23:01:17 +02:00
|
|
|
|
docker-compose exec $2 "/bin/bash"
|
2024-07-04 12:42:13 +02:00
|
|
|
|
fi
|
|
|
|
|
elif [[ $1 == "destroyall" ]]
|
|
|
|
|
then
|
|
|
|
|
destroyall
|
|
|
|
|
elif [[ $1 == "destroy" ]]
|
|
|
|
|
then
|
|
|
|
|
if [[ -z $2 ]]
|
|
|
|
|
then
|
|
|
|
|
EchoRouge "Vous devez precisez un service"
|
|
|
|
|
EchoRouge "nine.sh destroy monservice"
|
|
|
|
|
else
|
2024-07-24 16:11:40 +02:00
|
|
|
|
destroy$2
|
2024-07-04 12:42:13 +02:00
|
|
|
|
fi
|
2024-09-28 17:25:52 +02:00
|
|
|
|
elif [[ $1 == "pull" ]]
|
|
|
|
|
then
|
|
|
|
|
pull $2
|
2024-11-03 14:22:39 +01:00
|
|
|
|
elif [[ $1 == "pulluplogs" ]]
|
|
|
|
|
then
|
|
|
|
|
pull $2
|
|
|
|
|
up $2
|
|
|
|
|
docker-compose logs -f $2
|
2024-07-27 11:01:26 +02:00
|
|
|
|
elif [[ $1 == "services" ]]
|
|
|
|
|
then
|
|
|
|
|
services
|
2024-07-04 12:42:13 +02:00
|
|
|
|
elif [[ $1 == "logs" ]]
|
|
|
|
|
then
|
2024-07-05 23:01:17 +02:00
|
|
|
|
docker-compose logs -f $2
|
2024-07-04 12:42:13 +02:00
|
|
|
|
elif [[ $1 == "iswait" ]]
|
|
|
|
|
then
|
|
|
|
|
wait_for_container $2
|
|
|
|
|
elif [[ $1 == "regen" ]]
|
|
|
|
|
then
|
|
|
|
|
if [[ -z $2 ]]
|
|
|
|
|
then
|
|
|
|
|
destroyall
|
2024-07-27 10:19:39 +02:00
|
|
|
|
apache
|
|
|
|
|
template
|
2024-07-04 12:42:13 +02:00
|
|
|
|
up
|
|
|
|
|
else
|
2024-07-24 16:11:40 +02:00
|
|
|
|
destroy$2
|
2024-07-27 10:19:39 +02:00
|
|
|
|
apache
|
|
|
|
|
template
|
2024-07-24 16:11:40 +02:00
|
|
|
|
up$2
|
2024-07-04 12:42:13 +02:00
|
|
|
|
fi
|
2024-07-28 16:57:55 +02:00
|
|
|
|
elif [[ $1 == "regenlogs" ]]
|
|
|
|
|
then
|
|
|
|
|
if [[ -z $2 ]]
|
|
|
|
|
then
|
|
|
|
|
destroyall
|
|
|
|
|
apache
|
|
|
|
|
template
|
|
|
|
|
up
|
|
|
|
|
else
|
|
|
|
|
destroy$2
|
|
|
|
|
apache
|
|
|
|
|
template
|
|
|
|
|
up$2
|
|
|
|
|
fi
|
|
|
|
|
docker-compose logs -f $2
|
2024-10-26 12:16:37 +02:00
|
|
|
|
elif [[ $1 == "letsencrypt" ]]
|
|
|
|
|
then
|
|
|
|
|
Title ${NINEAPACHE_SERVICE_NAME^^} LETSENCRYPT
|
|
|
|
|
if [[ $NINEAPACHE_ACTIVATE == 1 && $NINEAPACHE_LOCAL == 1 ]]
|
|
|
|
|
then
|
|
|
|
|
docker-compose exec ${NINEAPACHE_SERVICE_NAME} /nine/addcertif.sh
|
|
|
|
|
else
|
|
|
|
|
EchoRouge "Service ${NINEAPACHE_SERVICE_NAME} non actif"
|
|
|
|
|
fi
|
2024-07-04 12:42:13 +02:00
|
|
|
|
else
|
|
|
|
|
EchoRouge "Action possible ="
|
|
|
|
|
EchoRouge "nine.sh > UP de l'ensemble des services actifs"
|
|
|
|
|
EchoRouge "nine.sh up > UP de l'ensemble des services actifs"
|
|
|
|
|
EchoRouge "nine.sh up monservice> UP de monservice"
|
2024-07-24 16:11:40 +02:00
|
|
|
|
EchoRouge "nine.sh uplogs > UP puis logs de l'ensemble des services actifs"
|
|
|
|
|
EchoRouge "nine.sh uplogs monservice> UP puis logs de monservice"
|
2024-07-04 12:42:13 +02:00
|
|
|
|
EchoRouge "nine.sh stop > STOP de l'ensemble des services"
|
2024-09-28 17:25:52 +02:00
|
|
|
|
EchoRouge "nine.sh stop monservice > STOP de monservice"
|
|
|
|
|
EchoRouge "nine.sh bash monservice > lance un terminel dans le conteneur de monservice"
|
|
|
|
|
EchoRouge "nine.sh destroyall > détruit l'ensemble des services avec l'ensemble des BDD et des volumes persistant"
|
|
|
|
|
EchoRouge "nine.sh destroy monservice > détruit monservices et si souhaitez sa BDD et ses volumes persistant"
|
|
|
|
|
EchoRouge "nine.sh pull > Mettre à jour l'ensemble des images"
|
|
|
|
|
EchoRouge "nine.sh pull monservice > Mettre à jour l'image de monservice"
|
2024-11-03 14:22:39 +01:00
|
|
|
|
EchoRouge "nine.sh pulluplogs > Mettre à jour l'ensemble des images et uplogs de l'ensemble des services"
|
|
|
|
|
EchoRouge "nine.sh pulluplogs monservice > Mettre à jour l'image de monservice et uplogs de mon service"
|
2024-07-27 11:01:26 +02:00
|
|
|
|
EchoRouge "nine.sh services > Liste des Services"
|
2024-07-04 12:42:13 +02:00
|
|
|
|
EchoRouge "nine.sh logs > LOGS de l'ensemble des services"
|
|
|
|
|
EchoRouge "nine.sh logs monservice > LOGS de monservice"
|
|
|
|
|
EchoRouge "nine.sh iswait monservice > monservice est-il en cours de construction"
|
|
|
|
|
EchoRouge "nine.sh regen > lance destroyall puis up sur l'ensemble des service"
|
|
|
|
|
EchoRouge "nine.sh regen monservice > lance destroy monservice puis up monservice"
|
2024-10-26 12:16:37 +02:00
|
|
|
|
EchoRouge "nine.sh letsencrypt > genere ou renouvelle le certificat letsencrypt"
|
2024-07-04 12:42:13 +02:00
|
|
|
|
fi
|
|
|
|
|
echo
|
2024-09-18 15:33:58 +02:00
|
|
|
|
echo
|