Files
wild-directory/nfs/scripts/check-nfs.sh

80 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Verify NFS server is reachable and the export path is available.
# Run before or after deployment to validate NFS connectivity.
set -e
set -o pipefail
if [ -z "${WILD_INSTANCE}" ] || [ -z "${WILD_API_DATA_DIR}" ]; then
echo "ERROR: WILD_INSTANCE and WILD_API_DATA_DIR must be set"
exit 1
fi
CONFIG_FILE="${WILD_API_DATA_DIR}/instances/${WILD_INSTANCE}/config.yaml"
NFS_HOST="$(yq '.apps.nfs.host' "${CONFIG_FILE}" 2>/dev/null | tr -d '"')"
NFS_PATH="$(yq '.apps.nfs.mediaPath' "${CONFIG_FILE}" 2>/dev/null | tr -d '"')"
if [ -z "${NFS_HOST}" ] || [ "${NFS_HOST}" = "null" ]; then
echo "ERROR: apps.nfs.host not set in config"
exit 1
fi
if [ -z "${NFS_PATH}" ] || [ "${NFS_PATH}" = "null" ]; then
echo "ERROR: apps.nfs.mediaPath not set in config"
exit 1
fi
echo "NFS host: ${NFS_HOST}"
echo "NFS path: ${NFS_PATH}"
# Resolve hostname to IP
if [[ "${NFS_HOST}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
NFS_IP="${NFS_HOST}"
else
NFS_IP=$(getent hosts "${NFS_HOST}" 2>/dev/null | awk '{print $1}' | head -n1 || true)
if [ -z "${NFS_IP}" ]; then
echo "ERROR: Cannot resolve hostname ${NFS_HOST}"
exit 1
fi
echo "Resolved to: ${NFS_IP}"
fi
# Check showmount
if ! command -v showmount >/dev/null 2>&1; then
echo "WARNING: showmount not available, skipping export check"
else
echo ""
echo "Checking NFS exports..."
if timeout 10 showmount -e "${NFS_IP}" >/dev/null 2>&1; then
if showmount -e "${NFS_IP}" | grep -q "${NFS_PATH}"; then
echo "OK: ${NFS_PATH} is exported"
else
echo "ERROR: ${NFS_PATH} not found in NFS exports:"
showmount -e "${NFS_IP}"
exit 1
fi
else
echo "ERROR: Cannot reach NFS server at ${NFS_IP}:2049"
exit 1
fi
fi
# Check k8s resources if KUBECONFIG is available
if [ -n "${KUBECONFIG}" ]; then
echo ""
echo "Checking Kubernetes resources..."
if kubectl get storageclass nfs >/dev/null 2>&1; then
echo "OK: StorageClass 'nfs' exists"
else
echo "WARNING: StorageClass 'nfs' not found (deploy NFS first)"
fi
if kubectl get pv nfs-media-pv >/dev/null 2>&1; then
echo "OK: PersistentVolume 'nfs-media-pv' exists"
kubectl get pv nfs-media-pv --no-headers
else
echo "WARNING: PersistentVolume 'nfs-media-pv' not found (deploy NFS first)"
fi
fi
echo ""
echo "NFS check complete."