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.