Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for JupyterHub with local spawner (in the venv) and PAM a… #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions scripts/conf_jupyterhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# script name: conf_jupyterhub.sh
# last modified: 2019/09/01
# credits: EWouters
# sudo: yes

script_name=$(basename -- "$0")
env="/home/pi/.venv/jns"

if ! [ $(id -u) = 0 ]; then
echo "usage: sudo ./$script_name"
exit 1
fi

# if jupyterhub directory exists, we keep it (-p)
# if configuration file exists, we overwrite it (-y)

# Make folder to store config
mkdir -p /etc/jupyterhub
cd /etc/jupyterhub
# Generate Config
$env/bin/jupyterhub -y --generate-config

target=/etc/jupyterhub/jupyterhub_config.py

# set up dictionary of changes for jupyterhub_config.py
declare -A arr
app='c.Spawner'
arr+=(["$app.cmd = "]="$app.cmd = ['$env/bin/jupyterhub-singleuser']")
arr+=(["$app.default_url = "]="$app.default_url = 'lab'")
arr+=(["$app.notebook_dir = "]="$app.notebook_dir = '/home/pi/notebooks'")
arr+=(["c.Authenticator.admin_users = "]="c.Authenticator.admin_users = {'pi'}")

# apply changes to jupyter_notebook_config.py

for key in ${!arr[@]};do
if grep -qF $key ${target}; then
# key found -> replace line
sed -i "/${key}/c ${arr[${key}]}" $target
else
# key not found -> append line
echo "${arr[${key}]}" >> $target
fi
done
34 changes: 34 additions & 0 deletions scripts/conf_service_jupyterhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# script name: conf_service_jupyterhub.sh
# last modified: 2019/09/01
# credits: mt08xx, EWouters
# sudo: yes

script_name=$(basename -- "$0")

if ! [ $(id -u) = 0 ]; then
echo "usage: sudo ./$script_name"
exit 1
fi

cat << 'ONE' | sudo tee /etc/systemd/system/jupyterhub.service
[Unit]
Description=JupyterHub

[Service]
Type=simple
ExecStart=/home/pi/.venv/jns/bin/jupyterhub -f /etc/jupyterhub/jupyterhub_config.py
User=root
Group=root
WorkingDirectory=/etc/jupyterhub
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
ONE

# start jupyterhub
systemctl daemon-reload
systemctl start jupyterhub
systemctl enable jupyterhub
24 changes: 24 additions & 0 deletions scripts/inst_jupyterhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# script name: inst_jupyterhub.sh
# last modified: 2019/09/01
# credits: EWouters
# sudo: yes

script_name=$(basename -- "$0")
env="/home/pi/.venv/jns"

if ! [ $(id -u) = 0 ]; then
echo "usage: sudo ./$script_name"
exit 1
fi

# apt install -y nodejs
# apt install -y npm
# apt install -y nodejs-legacy

su - pi <<'EOF'
source /home/pi/.venv/jns/bin/activate
pip3 install jupyterhub
EOF

npm install -g configurable-http-proxy # Not sure if this needs to be run as root