File size: 1,541 Bytes
511bc62 c0616b4 da5c857 c0616b4 da5c857 c0616b4 da5c857 c0616b4 da5c857 c0616b4 da5c857 ecd62c6 3b6b10b da5c857 c0616b4 ea37cb1 c0616b4 da5c857 c0616b4 da5c857 c0616b4 da5c857 c0616b4 da5c857 c0616b4 da5c857 c0616b4 da5c857 511bc62 ecd62c6 c0616b4 ecd62c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#!/bin/bash
# Function to handle errors
handle_error() {
echo "Error: $1"
exit 1
}
# Verify and create the /data directory if it doesn't exist
if [ ! -d "/data" ]; then
mkdir -p /data || handle_error "Could not create /data directory"
echo "/data directory created for persistent storage"
fi
# Verify write permissions for /data directory
if [ ! -w "/data" ]; then
echo "Warning: No write permissions for /data. Some data may not be persistent."
fi
# Read JupyterLab token from the mounted secret file
if [ -f "/run/secrets/JUPYTER_TOKEN" ]; then
export JUPYTER_TOKEN=$(cat /run/secrets/JUPYTER_TOKEN)
else
echo "JUPYTER_TOKEN secret not found. Using AUX_TOKEN as fallback."
export JUPYTER_TOKEN=${AUX_TOKEN:-}
fi
# Verify if the token is empty
if [ -z "$JUPYTER_TOKEN" ]; then
handle_error "JupyterLab token is empty"
fi
# Check for GPU availability
if command -v nvidia-smi &> /dev/null; then
echo "GPU detected. Configuring environment for GPU usage."
export NVIDIA_VISIBLE_DEVICES=all
export NVIDIA_DRIVER_CAPABILITIES=compute,utility
else
echo "No GPU detected. CPU will be used."
fi
# Start JupyterLab in the background
jupyter lab --ip=0.0.0.0 --port=${JUPYTERLAB_PORT} --no-browser --allow-root \
--NotebookApp.token=${JUPYTER_TOKEN} \
--notebook-dir=/data &
# Ensure the Nginx PID file is writable
touch /tmp/nginx.pid
chmod 644 /tmp/nginx.pid
# Start Nginx in the foreground
nginx -g "daemon off;" -c /etc/nginx/nginx.conf || handle_error "Failed to start Nginx" |