File size: 1,700 Bytes
511bc62
 
da5c857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31004c5
 
 
 
 
da5c857
 
 
 
 
 
 
 
 
 
 
 
 
31004c5
da5c857
511bc62
da5c857
b26378c
 
 
da5c857
31004c5
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
#!/bin/bash

# Función para manejar errores
handle_error() {
    echo "Error: $1"
    exit 1
}

# Verificar y crear el directorio /data si no existe
if [ ! -d "/data" ]; then
    mkdir -p /data || handle_error "No se pudo crear el directorio /data"
    echo "Directorio /data creado para almacenamiento persistente"
fi

# Verificar permisos del directorio /data
if [ ! -w "/data" ]; then
    echo "Advertencia: No se tienen permisos de escritura en /data. Algunos datos pueden no ser persistentes."
fi

# Asegurar que el usuario jovyan sea el propietario de /data
chown -R ${NB_UID}:${NB_GID} /data

# Verificar si el secreto JUPYTER_TOKEN existe y asignarlo a la variable de entorno
if [ -f "/run/secrets/JUPYTER_TOKEN" ]; then
    export JUPYTER_TOKEN=$(cat /run/secrets/JUPYTER_TOKEN)
elif [ -z "$JUPYTER_TOKEN" ]; then
    handle_error "El token de JupyterLab está vacío. Asegúrate de configurar el secreto JUPYTER_TOKEN en la configuración del Space."
fi

# Verificar disponibilidad de GPU
if command -v nvidia-smi &> /dev/null; then
    echo "GPU detectada. Configurando entorno para uso de GPU."
    export NVIDIA_VISIBLE_DEVICES=all
    export NVIDIA_DRIVER_CAPABILITIES=compute,utility
else
    echo "No se detectó GPU. Se utilizará CPU."
fi

# Iniciar JupyterLab en segundo plano
jupyter lab --ip=0.0.0.0 --port=${JUPYTERLAB_PORT} --no-browser --allow-root \
    --NotebookApp.base_url=/jupyter --NotebookApp.token=${JUPYTER_TOKEN} \
    --notebook-dir=/data &

# Asegurar que el archivo PID de Nginx sea escribible
touch /tmp/nginx.pid
chmod 644 /tmp/nginx.pid

# Iniciar Nginx en primer plano
nginx -g "daemon off;" -c /etc/nginx/nginx.conf || handle_error "Fallo al iniciar Nginx"