gpu_server_setup/setup_apps_miniforge.sh

132 lines
4.3 KiB
Bash
Raw Normal View History

2022-08-19 14:21:20 +00:00
#!/bin/bash
#variant to use conda insted of pip, tested
#Src: https://medium.com/swlh/how-to-install-jupyterhub-using-conda-without-runing-as-root-and-make-it-a-service-59b843fead12
# https://jupyterhub.readthedocs.io/en/1.2.1/installation-guide-hard.html
set -e
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
CERTIFICATE_HOSTNAME=$1
if [ -z "$CERTIFICATE_HOSTNAME" ]
then
echo "Please specify hostname for the certificate generation"
exit
fi
#apt-get install -y --no-install-recommends libnvinfer7=7.1.3-1+cuda11.0 \
# libnvinfer-dev=7.1.3-1+cuda11.0 \
# libnvinfer-plugin7=7.1.3-1+cuda11.0
#add public ssh keys
#if [ ! -s "~/.ssh/authorized_keys" ]; then
# cat id_*.pub >> ~/.ssh/authorized_keys
#fi
#echo ""
#echo "Install supermicro system tools..."
#apt-get update
#apt-get install -y ipmitool && modprobe ipmi_devintf
apt-get update
apt-get install -y language-pack-de python3.10-venv
echo "Install a recent notejs for jupyterhub from nodesource..."
#src: https://github.com/nodesource/distributions/blob/master/README.md
curl -fsSL https://deb.nodesource.com/setup_current.x | bash -
apt-get install -y nodejs
echo "create virtualenv and install JupyterHub..."
python3 -m venv /opt/jupyterhub/
/opt/jupyterhub/bin/python3 -m pip install wheel
/opt/jupyterhub/bin/python3 -m pip install jupyterhub jupyterlab
/opt/jupyterhub/bin/python3 -m pip install ipywidgets jupyterlab-git jupyter-server-proxy
npm install -g configurable-http-proxy
echo "setup jupyterhub config..."
mkdir -p /opt/jupyterhub/etc/jupyterhub/
cp jupyterhub_config_https.py /opt/jupyterhub/etc/jupyterhub/jupyterhub_config.py
echo "setup systemd service..."
mkdir -p /opt/jupyterhub/etc/systemd
cp jupyterhub_conda.service /opt/jupyterhub/etc/systemd/jupyterhub.service
ln -s /opt/jupyterhub/etc/systemd/jupyterhub.service /etc/systemd/system/jupyterhub.service
systemctl daemon-reload
systemctl enable jupyterhub.service
echo "Generate self signed certificate..."
mkdir -p /opt/jupyterhub/etc/jupyterhub/ssl-certs
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
-keyout /opt/jupyterhub/etc/jupyterhub/ssl-certs/jhubssl.key \
-out /opt/jupyterhub/etc/jupyterhub/ssl-certs/jhubssl.crt \
-subj "/C=DE/ST=NRW/L=na/O=na Systems/OU=Self_Signed/CN=$CERTIFICATE_HOSTNAME" \
-addext "subjectAltName=DNS:$CERTIFICATE_HOSTNAME"
#echo "jupyterhub.service status: (opens vim)"
#systemctl status jupyterhub.service
echo "Install conda..."
CONDA_DIR=/opt/conda
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
bash Miniforge3-$(uname)-$(uname -m).sh -b -p $CONDA_DIR
#symlinking the conda shell setup script to the profile drop in folder so that it gets run on login:
ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh
mkdir -p /opt/conda/envs/
#remove existing environment and ipykernel:
2022-09-20 11:45:36 +00:00
#/opt/conda/envs/default_python/jupyter kernelspec remove python3
#/opt/conda/bin/conda env remove -p /opt/conda/envs/default_python
2022-08-19 14:21:20 +00:00
#setup default conda environment
/opt/conda/bin/conda env create --prefix /opt/conda/envs/default_python -f work-environment.yml
2022-08-19 14:21:20 +00:00
#setup kernel for using the enviroment in jupyter lab
2022-09-20 11:45:36 +00:00
/opt/conda/envs/default_python/bin/python -m ipykernel install --name 'python3' --display-name "Python (default)"
2022-08-19 14:21:20 +00:00
2022-08-19 14:49:05 +00:00
#users have to setup their kernel like this:
2022-08-19 14:21:20 +00:00
#create conder enviroment:
#conda create ipykernel --name mypersonal_enviroment
#python -m ipykernel install --user --name mypersonal_enviroment --display-name "Python My Env"
#echo "Install Tensorflow..."
#conda install --yes tensorflow-gpu -c conda-forge
#Other tools:
#System monitoring
#echo "Install netdata..."
#wget -O /tmp/netdata-kickstart.sh https://my-netdata.io/kickstart.sh && sh /tmp/netdata-kickstart.sh
#echo "nvidia_smi: yes" >> /usr/lib/netdata/conf.d/python.d.conf
#service netdata restart
#on http://0.0.0.0:19999
#echo "Install gpuview..."
#/opt/jupyterhub/bin/python3 -m pip install gpuview
#/opt/jupyterhub/bin/python3 -m gpuview service --host 127.0.0.1 --port 9988 <-- fails
#echo "Disable services that delays startup by wating for network connectivity..."
#systemctl disable cloud-config
#systemctl disable cloud-final.service
#systemctl disable iscsid.service
#systemctl disable open-iscsi.service
echo "Start JupyterHub..."
systemctl start jupyterhub.service
echo ""
echo "Setup successfully finished"