-
Notifications
You must be signed in to change notification settings - Fork 9
/
03-jupyterconf.sh
executable file
·66 lines (49 loc) · 2.02 KB
/
03-jupyterconf.sh
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Set the files and the folders
CONFDIR="/etc/jupyterhub"
SERVDIR="/srv/jupyterhub"
LOGFILE="/var/log/jupyterhub.log"
CONFFILE=${CONFDIR}/jupyterhub.py
# Create the folders
mkdir -p $CONFDIR ${SERVDIR}/ssl &> /dev/null
# Set permissions
chmod 700 $CONFDIR $SERVDIR
# Create default configuration
jupyterhub --generate-config -f $CONFFILE
# Generate cookie secret
openssl rand -base64 2048 > ${SERVDIR}/cookie_secret
# Generate proxy auth token
PROXY_TOKEN=`openssl rand -hex 32`
# Copy over logo
cp data/logo.png ${SERVDIR}
# Get admin users
ADMINS=`python -c 'print(set(open("admins.list").read().strip().split("\n")))'`
# Setup configuration
echo "c.JupyterHub.proxy_auth_token = '$PROXY_TOKEN'" >> $CONFFILE
echo "c.JupyterHub.cookie_secret_file = '${SERVDIR}/cookie_secret'" >> $CONFFILE
echo "c.JupyterHub.cookie_max_age_days = 1" >> $CONFFILE
echo "c.JupyterHub.db_url = '${SERVDIR}/jupyterhub.sqlite'" >> $CONFFILE
echo "c.JupyterHub.extra_log_file = '${LOGFILE}'" >> $CONFFILE
echo "c.JupyterHub.logo_file = '${SERVDIR}/logo.png'" >> $CONFFILE
echo "c.Spawner.notebook_dir = '~/notebooks'" >> $CONFFILE
echo "c.Authenticator.admin_users = $ADMINS" >> $CONFFILE
# Restrict permissions
chmod 600 ${CONFDIR}/*
chmod 600 ${SERVDIR}/*
# Install systemd services
cp data/jupyterhub.service /etc/systemd/system
systemctl daemon-reload
systemctl enable jupyterhub.service jupyterhub-idle-killer.service
# Optional: Install cull_idle_servers
wget http://raw.githubusercontent.com/jupyterhub/jupyterhub/master/examples/cull-idle/cull_idle_servers.py \
-O ${SERVDIR}/cull-idle-servers
chmod +x ${SERVDIR}/cull-idle-servers
# Copy systemd file
cp data/jupyterhub-idle-killer.service /etc/systemd/system
# Generate API token
API_TOKEN=`openssl rand -hex 32`
# TODO: Pick an admin user here for the cull service
API_USER="lect1"
echo "c.JupyterHub.api_tokens = {'${API_TOKEN}' : '${API_USER}'}" >> $CONFFILE
sed -i "s/%%APITOKEN%%/${API_TOKEN}/" /etc/systemd/system/jupyterhub-idle-killer.service
systemctl enable jupyterhub-idle-killer.service