gpu_server_setup/setup_apps_conda.sh

144 lines
5.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 anaconda..."
#wget -O /tmp/anaconda3.sh https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
#bash /tmp/anaconda3.sh
curl https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmor > conda.gpg
install -o root -g root -m 644 conda.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://repo.anaconda.com/pkgs/misc/debrepo/conda stable main" | sudo tee /etc/apt/sources.list.d/conda.list
apt-get update
apt-get install -y conda
#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/
/opt/conda/bin/conda create --prefix /opt/conda/envs/default_python python=3.7 ipykernel --yes
/opt/conda/envs/default_python/bin/python -m ipykernel install --prefix /usr/local/ --name 'default_python' --display-name "Python (default)"
#/opt/conda/envs/python/bin/python -m ipykernel install --prefix=/opt/jupyterhub/ --name 'python' --display-name "Python (default)"
#install ofen used python packages for default environment
/opt/conda/bin/conda install h5py tqdm pandas pillow matplotlib ipympl matplotlib --yes -n default_python
/opt/conda/bin/conda install cantera --channel cantera --yes -n default_python
#remove ipykernel for base enviroment:
#jupyter kernelspec remove python3
#users have to setup there kernel like this:
#create conder enviroment:
#conda create ipykernel --name mypersonal_enviroment
#python -m ipykernel install --user --name mypersonal_enviroment --display-name "Python My Env"
#conda install --yes jupyterhub jupyterlab notebook configurable-http-proxy jupyterlab-git jupyter-server-proxy
#jupyter labextension install jupyter-matplotlib
#echo "Install Tensorflow..."
#conda install --yes tensorflow-gpu -c conda-forge
#echo "Install common Python libs..."
#conda install --yes h5py tqdm pandas ipywidgets pillow matplotlib ipympl opencv-python
#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
#sudo systemctl restart jupyterhub
echo ""
echo "Setup successfully finished"