File size: 1,297 Bytes
511bc62
 
c0616b4
da5c857
 
 
 
 
c0616b4
da5c857
c0616b4
 
da5c857
 
c0616b4
da5c857
c0616b4
da5c857
 
3b6b10b
 
 
 
da5c857
c0616b4
ea37cb1
c0616b4
da5c857
 
c0616b4
da5c857
c0616b4
da5c857
 
 
c0616b4
da5c857
 
c0616b4
da5c857
c0616b4
da5c857
511bc62
c0616b4
3b6b10b
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
#!/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

# Use the AUX_TOKEN environment variable if JUPYTER_TOKEN is not set
if [ -z "$JUPYTER_TOKEN" ]; then
    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 &

# Start Nginx in the foreground
nginx -g "daemon off;" || handle_error "Failed to start Nginx"