Run jupyter notebook on system boot


What is the best way to run Jupiter notebook command on system startup so I don’t need to ssh connect? I would like to be able to use the notebooks after aws instance start by just entering the address in a browser. Is it possible?

(Caleb Crome) #2

I do it with crontab.

Edit your crontab with this command:

export EDITOR=nano
crontab -e

And add this line to the bottom

@reboot cd /home/ubuntu; source ~/.bashrc;  /home/ubuntu/anaconda2/bin/jupyter notebook

Save, quit, and reboot. with

sudo reboot

Note: you get charged a full hour every time you start an AWS instance. I don’t think you get charged for just doing a reboot.

(james wolf) #3

oh, thank you for this. I tried several things that did not seem to work. I should have looked on the forums first! Lesson learned

(James Puderer) #4

Very nice!

Can I suggest a small improvement?

You might as well make it work regardless of the username by using ‘~’ exclusively to refer to the home directory. Also, it’s handy to output the logs somewhere, in case of problems…

@reboot cd ~/deeplearning; source ~/.bashrc; ~/anaconda3/bin/jupyter notebook >>~/cronrun.log 2>&1

(Runqi Yang) #5

Just a reminder for those who may misunderstand the “reboot” thing (like me): doing a reboot will not be charged again, but stopping an instance and restarting it immediately will still result in doubled cost in this hour.

(Brendan Fortuner) #6

I found systemd works really well for me on my Ubuntu server. There are a bunch of ways to do this, but using systemd on Ubuntu you can set up an “always running” jupyter workplace (e.g. a directory with all your projects). Systemd will handle restarting for you after reboots or crashes.

Create the file: /etc/systemd/system/jupyter.service

Description=Jupyter Workplace

ExecStart=/home/bfortuner/anaconda3/bin/jupyter-notebook --config=/home/bfortuner/.jupyter/


Then, run the commands

systemctl enable jupyter.service
systemctl daemon-reload
systemctl restart jupyter.service


Will this start jupyter notebook after a shutdown/start as well, or only after a reboot? (the @reboot bit makes me wonder)


I find that source ~/.bashrc was not executed by cron. I keep getting the following error when importing

ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.
Using Theano backend.


I followed @brendan’s systemd way. Here’s the same steps for a paperspace machine:

Create the file: sudo nano /etc/systemd/system/jupyter.service

Description=Jupyter Workplace

ExecStart=/home/paperspace/anaconda3/bin/jupyter-notebook --config=/home/paperspace/.jupyter/


Then, run the commands

sudo systemctl enable jupyter.service
sudo systemctl daemon-reload
sudo systemctl restart jupyter.service

You still need to link machine:8888 to your localhost:8888. So I just added this line to the end of ~/.bashrc:

systemctl status jupyter.service

So I still have to SSH to the machine, but it will display the link with token automatically (using the last steps in the setup).

(Michael Hemenway) #10

Thanks for this helpful modification of the systemd setup for use in Paperspace. I had to make one small change to make sure I was running jupyter from the fastai conda env, otherwise some packages were not found on import. So, I simply modified the ExecStart line to read:

ExecStart=/home/paperspace/anaconda3/envs/fastai/bin/jupyter-notebook --config=/home/paperspace/.jupyter/

Seems to be working perfectly now. Thanks so much!