2024-02-17 12:21:51 -08:00
|
|
|
#!/bin/bash
|
2024-02-29 15:26:48 -08:00
|
|
|
#set -x # debugging flag
|
2024-02-17 12:21:51 -08:00
|
|
|
|
2024-02-29 19:53:36 -08:00
|
|
|
# Clean up any remnants from unclean shutdown
|
|
|
|
docker stop $(docker ps -q) # shut down running containers
|
|
|
|
docker rm $(docker ps -aq) # remove all containers
|
|
|
|
|
2024-02-17 12:21:51 -08:00
|
|
|
# Check for network mounted devices
|
|
|
|
# NAS SMB
|
|
|
|
if ! mount -t cifs | grep -q '/mnt/nas'; then
|
2024-02-21 13:39:38 -08:00
|
|
|
echo " ==== NAS SMB shares not mounted"
|
2024-02-29 01:39:44 -08:00
|
|
|
echo " ==== Won't online stacks which depend on SMB shares"
|
|
|
|
SMB_ONLINE=false
|
|
|
|
else
|
|
|
|
SMB_ONLINE=true
|
2024-02-17 12:21:51 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# NAS iSCSI
|
|
|
|
if ! sudo iscsiadm -m session | grep -q 'iqn.2020-03.net.jafner:fighter'; then
|
2024-02-21 13:39:38 -08:00
|
|
|
echo " ==== NAS iSCSI session not connected"
|
|
|
|
if ! mount -t ext4 | grep -q '/mnt/iscsi'; then
|
|
|
|
echo " ==== /mnt/iscsi not mounted"
|
2024-02-29 01:39:44 -08:00
|
|
|
echo " ==== Won't online stacks which depend on iSCSI shares"
|
2024-02-21 13:39:38 -08:00
|
|
|
fi
|
2024-02-29 01:39:44 -08:00
|
|
|
ISCSI_ONLINE=false
|
|
|
|
else
|
|
|
|
ISCSI_ONLINE=true
|
2024-02-17 12:21:51 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
for stack in /home/admin/homelab/fighter/config/*; do
|
|
|
|
cd $stack
|
2024-02-29 15:26:48 -08:00
|
|
|
if ! docker compose config > /dev/null; then
|
2024-02-21 13:39:38 -08:00
|
|
|
echo " ==== Invalid compose config: $stack"
|
|
|
|
fi
|
2024-02-29 01:39:44 -08:00
|
|
|
COMPOSE_CONFIG_TEXT=$(docker compose config)
|
|
|
|
|
2024-02-29 17:23:34 -08:00
|
|
|
# If the stack needs iSCSI and iSCSI isn't available, skip.
|
|
|
|
if ( echo $COMPOSE_CONFIG_TEXT | grep -q /mnt/iscsi ) && ! $ISCSI_ONLINE; then
|
|
|
|
echo " ==== $stack is dependent on iSCSI and iSCSI is offline, skipping..."
|
|
|
|
# Else if the stack needs SMB and SMB isn't available, skip.
|
|
|
|
elif ( echo $COMPOSE_CONFIG_TEXT | grep -q /mnt/nas ) && ! $SMB_ONLINE; then
|
|
|
|
echo " ==== $stack is dependent on SMB and SMB is offline, skipping..."
|
|
|
|
# Else the stack can be onlined. We also add it to a list of onlined services
|
2024-02-29 01:39:44 -08:00
|
|
|
else
|
2024-02-29 17:23:34 -08:00
|
|
|
echo " ==== Bringing up $stack "
|
|
|
|
STACKS_ONLINE+="$(echo $stack | xargs basename)\n"
|
|
|
|
echo -n " ==== Time: "
|
|
|
|
( time docker compose --progress quiet up -d ) 2>&1 | grep real | cut -f 2
|
|
|
|
echo " ==== Done!"
|
2024-02-29 01:39:44 -08:00
|
|
|
fi
|
|
|
|
|
2024-02-17 12:21:51 -08:00
|
|
|
cd /home/admin/homelab/fighter/config/
|
2024-02-29 01:39:44 -08:00
|
|
|
# make sure to overwrite the config text to prevent leaking secrets
|
|
|
|
COMPOSE_CONFIG_TEXT=""
|
2024-02-17 12:21:51 -08:00
|
|
|
done
|
2024-02-20 19:13:01 -08:00
|
|
|
|
2024-02-29 17:23:34 -08:00
|
|
|
echo " ==== List of stacks online:"
|
|
|
|
echo -e "$STACKS_ONLINE"
|
|
|
|
|
2024-02-20 19:13:01 -08:00
|
|
|
# extra thing because my keycloak healthcheck doesn't work properly
|
|
|
|
|
2024-02-21 13:39:38 -08:00
|
|
|
echo " ==== Wait 15s, then bring Keycloak forwardauth containers online"
|
2024-02-20 19:13:01 -08:00
|
|
|
cd /home/admin/homelab/fighter/config/keycloak
|
|
|
|
sleep 15
|
2024-02-29 15:28:06 -08:00
|
|
|
docker start keycloak_forwardauth keycloak_forwardauth-privileged
|