Autostart Jupyter Notebook

I’m not sure if this has been posted before, but I figured I would share something I found useful. I recently blogged about using the Deep Learning AMI, and updated it for the AMI as well, and shared some issues I encountered and some solutions.

Since I was always stopping the instance when the I’m not using it, I wanted to find a way to autostart Jupyter when I start up the instance again. Here’s some steps to do that exactly on the fastai AWS AMI:

  1. Create in your home directory
  2. Add the following:
export PATH="$PATH:/home/ubuntu/src/anaconda3/bin"
jupyter notebook --notebook-dir=/home/ubuntu/ --profile=nbserver > /tmp/ipynb.out 2>&1 &
  1. You can change notebook-dir to wherever you want for example /home/ubuntu/fastai/courses/dl1/ if you want to point it directly to the course notebooks
  2. Edit /etc/rc.local and add the following line before exit 0
    su ubuntu -c 'bash /home/ubuntu/'

I’m not sure if this very relevant to people using SSH tunnelling, as I’m mainly accessing using the IP instead, so this works great for my use case. I hope you find this useful!


Is there an easy way to restart jupyter with this solution? I did this for a while, but I had a hard time restarting jupyter because it was in another session so I had to lookup and kill the process in order to restart it.

Yeah, I ran into this problem and found it annoying as well! An easy way to kill it without necessarily looking up the process ID is using pkill jupyter. You can easily put these into bash scripts where for e.g. does pkill jupyter, and another would just simply call the 2 other bash scripts to stop then start!


Very cool, those are all way better than the way I was using.

1 Like

You could use systemctl
Description=Service for jupyter cpu notebook

SyslogIdentifier=jupyter cpu notebook


To run the script to auto start and stop. More info at