2022年11月28日 星期一

Debian 11 安裝 JupyterHub

apt-get install nodejs npm pip
python3 -m pip install jupyterhub
npm install -g configurable-http-proxy
python3 -m pip install jupyterlab notebook

pip install jupyterlab-language-pack-zh-TW

編輯  /etc/systemd/system/jupyterhub.service
# Template file for JupyterHub systemd service
# Uses simple string.format() for 'templating'
# /etc/systemd/system/jupyterhub.service
# /etc/systemd/system/multi-user.target.wants/jupyterhub.service
[Unit]
#Requires=traefik.service
#After=traefik.service

[Service]
User=root
Restart=always
WorkingDirectory=/opt/jupyterhub

# Protect bits that are normally shared across the system
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes

#Environment=TLJH_INSTALL_PREFIX=/opt/tljh
# Run upgrade-db before starting, in case Hub version has changed

# This is a no-op when no db exists or no upgrades are needed
ExecStart=/usr/local/bin/jupyterhub

[Install]
# Start service when system boots
WantedBy=multi-user.target

編輯 /opt/jupyterhub/bootstrap.sh
#!/bin/bash
USER=$1
USERHOME=$(eval "echo ~${USER}")
[ "$USER" == "" ]&&exit 0;
[ -d "$USERHOME" ]&&exit 0;

mkdir -p $(dirname $USERHOME);
cp -r /etc/skel $USERHOME;
uid=$(id $USER|tr \( \ |xargs -n 1|grep uid|cut -d= -f2)
gid=$(id $USER|tr \( \ |xargs -n 1|grep gid|cut -d= -f2)
chown -R $uid.$gid $USERHOME  && chmod 0700 $USERHOME;
exit 0

編輯/opt/jupyterhub/jupyterhub_config.py 加入
import subprocess
def pre_spawn_hook(spawner):
    username = spawner.user.name
    subprocess.check_call(['./bootstrap.sh', username])
c.Spawner.pre_spawn_hook = pre_spawn_hook


沒有留言: