8

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.

1
  • I tried on Ubuntu 20.04 and it was resolved when I activated the respective conda environment. Commented Feb 21, 2024 at 18:04

3 Answers 3

10

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.

Sign up to request clarification or add additional context in comments.

5 Comments

@CarlosSouza Can you post a few more details as a separate question?
Sure: I did exact as you described: - created a /etc/rc.local - included the line as you showed on an Ubuntu 18.04, EC2 instance. Nothing happens.
@CarlosSouza: Best to open a new question or discuss it in chat: chat.stackoverflow.com/rooms/205822/…
@CarlosSouza: Can you try to execute your /etc/rc.local file via and check if there are any error messages?
@CésarArquero: Just got a fresh install of Ubuntu 20.04 and updated the answer.
2

this one worked for me. Put this in your /etc/rc.local.

sudo -u <username> nohup /home/<username>/.local/bin/jupyter-notebook --ip 0.0.0.0 --port 8888 --no-browser --notebook-dir=/home/<username>/<notebook_dir>& 

In my case, /etc/rc.local is not available at the first time, so you need to create this first. Then, make it executable.

sudo chmod +x /etc/rc.local 

Here is the content of my rc.local look like.

#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. sudo -u my_username nohup /home/my_username/.local/bin/jupyter-notebook --ip 0.0.0.0 --port 8888 --no-browser --notebook-dir=/home/my_username/notebook& exit 0 

Comments

1
+50

In my case, in ubuntu 20.04 the "/etc/rc.local" way didn't work. I've solved in two steps: (1) creating and executable file that work just with double click or enter; and (2) addind the execution to startup applications in gnome.

Here is in detail:

  1. Create the file in the place you want and add executable option. Here is the one line of code to create the file in the USER folder: cd /home/USER & touch jupyterlab.sh & sudo chmod u+x jupyterlab.sh

  2. Add the corresponding execution excript to the file. In my case I'm running jupyter-lab (locate the program with which jupyter-lab), with an ip and port as I'm using it as server.

Here is what the file contains:

#!/bin/bash /home/USER/anaconda3/bin/jupyter-lab --ip 192.168.1.32 --port 9000 --no-browser & exit 
  1. (optional) Make the file executable also by double click and enter goint to preferences in dolphin (like here).

  2. Add the file and .sh extension to the startup aplications.

enter image description here

May be it seems long, but it has the advantages of getting an executable file that can initialize (or not) just with a few clicks.

2 Comments

In my case, it took a little bit of time to start up script to start jupyter, but this solution really works really well. I guess the lag time depends on the computer. This solution easy to execute and importantly does not involve the use of sudo privileges. So less likely to mess up the system upon a silly mistake. For making the script executable chmod +x jupyterlab.sh will also do.
I had a few suggestions to improve the answer but could not add them in, because the "edit queue is full". Could you please add them from this link: pastebin.com/QcPfVcKG

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.