Skip to content

Instantly share code, notes, and snippets.

@shr00mie
Last active July 20, 2019 10:41
Show Gist options
  • Select an option

  • Save shr00mie/0f45256d99d9144086ab6ae5c2ca93f2 to your computer and use it in GitHub Desktop.

Select an option

Save shr00mie/0f45256d99d9144086ab6ae5c2ca93f2 to your computer and use it in GitHub Desktop.
Jupyterlab Install + Service on Ubuntu Server 16.04LTS
#!/bin/bash
# variables
read -p $'
\e[32mServer static IP address\e[m: ' ipAddress
echo -e "\n...\e[32mGenerating random token\e[m..."
token=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 30 | head -n 1)
echo -e "\n...\e[32mAdding Jonathon F Python 3.6 PPA\e[m..."
sudo add-apt-repository ppa:jonathonf/python-3.6
echo -e "\n...\e[32mUpdating system\e[m..."
sudo apt update && sudo apt upgrade -y
echo -e "\n...\e[32mInstalling python 3.6, python 3.6 dev, and python-pip\e[m..."
sudo apt install python3.6 python3.6-dev python-pip -y
echo -e "\n...\e[32mInstall Cleanup\e[m..."
sudo apt autoclean && sudo apt autoremove -y
echo -e "\n...\e[32mUpgrading pip\e[m..."
sudo -H pip install --upgrade pip
echo -e "\n...\e[32mInstalling Jupyter\e[m..."
sudo -H pip install jupyter
echo -e "\n...\e[32mGenerating jupyter config file\e[m..."
jupyter-notebook --generate-config
echo -e "\n...\e[32mTweaking config file\e[m..."
# allow connections from other devices
# listen on static IP
# don't open browser on start
# set port
# set token
sudo sed -i.back "s/#c.NotebookApp.allow_origin = ''/c.NotebookApp.allow_origin = '*'/ ; s/#c.NotebookApp.ip = 'localhost'/c.NotebookApp.ip = '$ipAddress'/ ; s/#c.NotebookApp.open_browser = True/c.NotebookApp.open_browser = False/ ; s/#c.NotebookApp.port = 8888/c.NotebookApp.port = 8888/ ; s/#c.NotebookApp.token = '<generated>'/c.NotebookApp.token = '$token'/" ~/.jupyter/jupyter_notebook_config.py
echo -e "\n...\e[32mCreating service user for Jupyter Notebook service\e[m..."
sudo adduser -q --system --shell /usr/sbin/nologin --group JupyterNotebook
echo -e "\n...\e[32mCreating Jupyter Notebook service\e[m..."
cat << EOF | sudo tee /etc/systemd/system/jupyter.service
[Unit]
Description=Jupyter Notebook Service
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/usr/local/bin/jupyter-notebook --config=/home/JupyterNotebook/.jupyter/jupyter_notebook_config.py
User=JupyterNotebook
Group=JupyterNotebook
Restart=always
RestartSec=10
#KillMode=mixed
[Install]
WantedBy=multi-user.target
EOF
echo -e "\n...\e[32mCopying Jupyter Notebook configuration to service user home directory\e[m..."
sudo mkdir /home/JupyterNotebook/.jupyter
sudo cp ~/.jupyter/jupyter_notebook_config.py /home/JupyterNotebook/.jupyter/jupyter_notebook_config.py
sudo chown JupyterNotebook:JupyterNotebook /home/JupyterNotebook/.jupyter
sudo chown JupyterNotebook:JupyterNotebook /home/JupyterNotebook/.jupyter/jupyter_notebook_config.py
echo -e "\n...\e[32mReloading systemctl daemon after creating service entry\e[m..."
sudo systemctl daemon-reload
echo -e "\n...\e[32mEnabling Jupyter Notebook service\e[m..."
sudo systemctl enable jupyter.service
echo -e "\n...\e[32mStarting Jupyter Notebook service\e[m..."
sudo systemctl start jupyter.service
echo -e "\n...\e[32mChecking status of Jupyter Notebook service\e[m..."
sudo systemctl status jupyter.service
echo -e "\n...\e[32mCopy the below entry and paste it into your Atom configuration file under \"Hydrogen:\"\e[m..."
echo "gateways: \"[{ \"name\" : \"Jupiter Notebook - Ubuntu Server 16.04\" , \"options\" : { \"baseUrl\" : \"http://$ipAddress:8888\" , \"token\" : \"$token\" } }]\""
echo -e "\n...\e[32mYou should be able to test the installation by opening a browser and opening the below URL\e[m..."
echo "http://$ipAddress:8888/?token=$token/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment