homelab/fighter/scripts/startup.sh
Joey Hafner 4f87418d80
Some checks are pending
Deploy to Fighter / Deploy (push) Waiting to run
Deploy to Fighter / Notify (push) Waiting to run
Improve handling of network shares offline
Allows the script to online stacks which don't need the SMB or iSCSI shares.
2024-02-29 01:39:44 -08:00

62 lines
2.1 KiB
Bash

#!/bin/bash
# Check for network mounted devices
# NAS SMB
if ! mount -t cifs | grep -q '/mnt/nas'; then
echo " ==== NAS SMB shares not mounted"
echo " ==== Won't online stacks which depend on SMB shares"
SMB_ONLINE=false
else
SMB_ONLINE=true
fi
# NAS iSCSI
if ! sudo iscsiadm -m session | grep -q 'iqn.2020-03.net.jafner:fighter'; then
echo " ==== NAS iSCSI session not connected"
if ! mount -t ext4 | grep -q '/mnt/iscsi'; then
echo " ==== /mnt/iscsi not mounted"
echo " ==== Won't online stacks which depend on iSCSI shares"
fi
ISCSI_ONLINE=false
else
ISCSI_ONLINE=true
fi
for stack in /home/admin/homelab/fighter/config/*; do
cd $stack
if ! docker compose config; then
echo " ==== Invalid compose config: $stack"
fi
COMPOSE_CONFIG_TEXT=$(docker compose config)
# The logic below is a little obtuse.
# If both SMB and ISCSI are online, we can online the stack no worries.
# If this test fails we know *at least one* of the share services is offline.
# So for the next two we check if the other service is online *and* we don't
# need the one that must be offline.
# If all of those fail, we know the stack is dependent on an offline service
# So we just skip the stack.
if (SMB_ONLINE=true && ISCSI_ONLINE=true); then
echo " ==== Bringing up $stack"
docker compose up -d
elif (! echo $COMPOSE_CONFIG_TEXT | grep -q /mnt/nas && ISCSI_ONLINE=true); then
echo " ==== Bringing up $stack"
docker compose up -d
elif (! echo $COMPOSE_CONFIG_TEXT | grep -q /mnt/iscsi && SMB_ONLINE=true); then
echo " ==== Bringing up $stack"
docker compose up -d
else
echo " ==== Skipping stack $stack"
fi
cd /home/admin/homelab/fighter/config/
# make sure to overwrite the config text to prevent leaking secrets
COMPOSE_CONFIG_TEXT=""
done
# extra thing because my keycloak healthcheck doesn't work properly
echo " ==== Wait 15s, then bring Keycloak forwardauth containers online"
cd /home/admin/homelab/fighter/config/keycloak
sleep 15
docker compose up -d