Run Jupyter-notebook on boot on Ubuntu

Viewed 15828

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.

3 Answers

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

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.

Related