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?
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
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.
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
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
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.
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
[Unit] Description=Jupyter Workplace [Service] Type=simple PIDFile=/run/jupyter.pid ExecStart=/home/bfortuner/anaconda3/bin/jupyter-notebook --config=/home/bfortuner/.jupyter/jupyter_notebook_config.py User=bfortuner Group=bfortuner WorkingDirectory=/home/bfortuner/workplace Restart=always RestartSec=10 [Install] WantedBy=multi-user.target
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 utils.py
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
[Unit] Description=Jupyter Workplace [Service] Type=simple PIDFile=/run/jupyter.pid ExecStart=/home/paperspace/anaconda3/bin/jupyter-notebook --config=/home/paperspace/.jupyter/jupyter_notebook_config.py User=paperspace Group=paperspace WorkingDirectory=/home/paperspace/fastai Restart=always RestartSec=10 [Install] WantedBy=multi-user.target
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
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).