From 34308d2a105a2e7ebdf0b702ebc4c0e4415e5ec3 Mon Sep 17 00:00:00 2001 From: Joey Hafner Date: Fri, 19 Aug 2022 10:21:26 -0700 Subject: [PATCH] Init nas_up.sh Format update for compose_up.sh Format update for compose_down.sh --- homelab/server/scripts/nas_up.sh | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 homelab/server/scripts/nas_up.sh diff --git a/homelab/server/scripts/nas_up.sh b/homelab/server/scripts/nas_up.sh new file mode 100644 index 00000000..34eae27e --- /dev/null +++ b/homelab/server/scripts/nas_up.sh @@ -0,0 +1,41 @@ +#!/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 +## + +## This block checks all projects within the ~/homelab/server/config directory for NAS-dependence +NAS_DEPENDENTS="" +for project in $(find ~/homelab/server/config -maxdepth 1 -mindepth 1 -path ~/homelab/server/config/minecraft -prune -o -print | cut -d "/" -f7) +do + echo "======== CHECKING $project ========" + cd ~/homelab/server/config/$project + docker-compose config + 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 + echo "======== SHUTTING DOWN $project ========" + cd ~/homelab/server/config/$project + docker-compose up -d +done \ No newline at end of file