2022-08-19 10:21:26 -07:00
#!/bin/bash
## This block checks all loaded (running or stopped) containers for nas-dependent mounts and adds them (by container name) to the NAS_DEPENDENTS variable.
# NAS_DEPENDENTS=""
# for CONTAINER_ID in $(docker ps -aq) # get list of all loaded containers (running and stopped)
# do
# CONTAINER_NAME=$(docker ps -aq --filter "id=$CONTAINER_ID" --format '{{.Names}}') # get the container's name
# CONTAINER_MOUNTS=$(docker inspect --format '{{range .Mounts}}{{println .Source}}{{end}}' $CONTAINER_ID) # print the container's volume mounts
# echo "$CONTAINER_MOUNTS" | grep -q /mnt/nas
# MATCH=$?
# if [ $MATCH == 0 ]; then
# NAS_DEPENDENTS+="$CONTAINER_NAME\n"
# fi
# done
##
2023-03-27 09:27:46 -07:00
## This block checks all projects within the ~/homelab/jafner-net/config directory for NAS-dependence
2022-08-19 10:21:26 -07:00
NAS_DEPENDENTS = ""
2023-03-27 09:27:46 -07:00
for project in $( find ~/homelab/jafner-net/config -maxdepth 1 -mindepth 1 -path ~/homelab/jafner-net/config/minecraft -prune -o -print | cut -d "/" -f7)
2022-08-19 10:21:26 -07:00
do
echo " ======== CHECKING $project ======== "
2023-03-27 09:27:46 -07:00
cd ~/homelab/jafner-net/config/$project
2022-08-19 10:21:26 -07:00
docker-compose config | grep -q /mnt/nas
MATCH = $?
if [ $MATCH = = 0 ] ; then
NAS_DEPENDENTS += " $project \n "
fi
done
echo -e " $NAS_DEPENDENTS "
## This block runs docker-compose down for
## all projects found by the previous block
for project in $( echo -e " $NAS_DEPENDENTS " )
do
2022-08-19 11:06:30 -07:00
echo " ======== STARTING UP $project ======== "
2023-03-27 09:27:46 -07:00
cd ~/homelab/jafner-net/config/$project
2022-08-19 10:21:26 -07:00
docker-compose up -d
done