Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Jupyter-notebook on boot on Ubuntu

I have an Ubuntu 16.04 Virtual Machine with anaconda installed, And I want it to launch Jupyter-notebook on startup with the correct configuration file (ip address, port, password,...)

This configuration is specified in /home/user/.jupyter/jupyter_notebook_config.py

When I'm logged as user and in the home directory(/home/user/) it does launch the correct config file.

But when using the command

jupyter-notebook

During startup with rc.local or using crontab it's doesn't load my configuration file, and have not the correct running directory.

like image 660
Simon Houdayer Avatar asked May 28 '17 20:05

Simon Houdayer


People also ask

How do I start a Jupyter Notebook in Ubuntu?

To install Jupyter Notebook on Ubuntu, we need to set up Anaconda environments for JupyterLab: 1. SSH to your server, open your terminal and run the following apt update and apt install command. This command updates your server's package index and installs the dependencies required to add new repositories over HTTPS.

How do I start my Jupyter Notebook on startup?

To launch Jupyter Notebook App: Click on spotlight, type terminal to open a terminal window. Enter the startup folder by typing cd /some_folder_name .

How do I run a Jupyter Notebook in Linux command line?

How to open Jupyter Notebook. To launch a Jupyter notebook, open your terminal and navigate to the directory where you would like to save your notebook. Then type the command jupyter notebook and the program will instantiate a local server at localhost:8888 (or another specified port).


1 Answers

Very similar question and answer: How to start ipython notebook server at boot as daemon

You could add the following line to your /etc/rc.local file

su <username> -c "jupyter notebook --config=/location/of/your/config/file/.jupyter/jupyter_notebook_config.py --no-browser --notebook-dir=/location/of/yournotebooks" &

e.g.

su simon -c "jupyter notebook --config=/home/simon/.jupyter/jupyter_notebook_config.py --no-browser --notebook-dir=/home/simon/notebooks" &

su <username> -c makes sure that the notebook is not executed as root but with the specified user account.``

--config and --notebook-dir specify the location of your config file and your notebook folder (http://jupyter-notebook.readthedocs.io/en/latest/config.html)


For systems using systemd (Ubuntu 16 and later) the following approach also works:

  • Create a service file in /etc/systemd/system/, e.g. jupyter.service with the following content (replace YourUserName with your username)

    [Unit]
    After=network.service
    
    [Service]
    ExecStart=jupyter notebook
    User=YourUserName
    
    [Install]
    WantedBy=default.target
    
  • Enable the service with sudo systemctl enable jupyter.service

  • Start the service with sudo systemctl start jupyter.service

You should set a password for your Jupyter server because you won't have access to the token.

like image 188
Maximilian Peters Avatar answered Oct 31 '22 05:10

Maximilian Peters