Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A systemd script for running a Jupyter notebook server.
# After Ubuntu 16.04, Systemd becomes the default.
# It is simpler than https://gist.github.com/Doowon/38910829898a6624ce4ed554f082c4dd
[Unit]
Description=Jupyter Notebook
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/phil/Enthought/Canopy_64bit/User/bin/jupyter-notebook --config=/home/phil/.jupyter/jupyter_notebook_config.py
User=phil
Group=phil
WorkingDirectory=/home/phil/Notebooks/
Restart=always
RestartSec=10
#KillMode=mixed
[Install]
WantedBy=multi-user.target
@whophil

This comment has been minimized.

Copy link
Owner Author

whophil commented Aug 14, 2016

Following the instructions of https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples, place this file in:

/usr/lib/systemd/system/jupyter.service

Then execute

sudo systemctl enable jupyter.service

Reload the systemd daemona and restart the service

sudo systemctl daemon-reload
sudo systemctl restart jupyter.service
@whophil

This comment has been minimized.

Copy link
Owner Author

whophil commented Aug 27, 2016

Ran into some problems with calling jupyter notebook

`'notebook' is not a Jupyter command`.

Switched to explicit jupyter-notebook call instead.

@DomHudson

This comment has been minimized.

Copy link

DomHudson commented Oct 24, 2017

Thanks!

@Kevintso

This comment has been minimized.

Copy link

Kevintso commented Dec 4, 2017

why occurs this error, with or without config.py
● jupyter.service
Loaded: loaded (/lib/systemd/system/jupyter.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Mon 2017-12-04 23:38:01 UTC; 3s ago
Process: 17830 ExecStart=/home/ubuntu/anaconda3/envs/tensorflow_p36/bin/jupyter-notebook (code=exited, status=200/CHDIR)
Main PID: 17830 (code=exited, status=200/CHDIR)

@archi18

This comment has been minimized.

Copy link

archi18 commented Mar 14, 2018

Hi @Kevintso ,
From exit status (code=exited, status=200/CHDIR) , it seems that either you do not have specified working directory or user and group you have specified does not have right permission in that directory.
Working directory (WorkingDirectory=) must be present , and make sure it has the right permissions.

Hope this helps you.

@WesternGun

This comment has been minimized.

Copy link

WesternGun commented May 31, 2018

In my case I have a 203/EXEC error, and after checking this, I have found that I have to add /bin/bash -c before the whole command, so it becomes:

ExecStart=/bin/bash -c "/usr/bin/jupyter notebook --config=/home/westerngun/.jupyter/jupyter_notebook_config.py --debug > /another/programming/jupyter/notebook.log 2>&1"

(last part is for log, you can go without it)

I am with CentOS 7. After this change this service finally gets working. So maybe the OP lacks it?

@aeoleader

This comment has been minimized.

Copy link

aeoleader commented Nov 28, 2018

18.04 won't start the service. After executing `sudo systemctl restart jupyter.service', it gives me Exec format error.

@G-Guillard

This comment has been minimized.

Copy link

G-Guillard commented Mar 21, 2019

If encountering the following errors :

 Main PID: 24251 (code=exited, status=1/FAILURE)

Mar 21 13:48:21 ip-172-31-26-72 systemd[1]: jupyter.service: Main process exited, code=exited, status=1/FAILURE
Mar 21 13:48:21 ip-172-31-26-72 systemd[1]: jupyter.service: Unit entered failed state.
Mar 21 13:48:21 ip-172-31-26-72 systemd[1]: jupyter.service: Failed with result 'exit-code'.

Check /var/log/syslog for a more verbose message. It may be that

ValueError: certfile "certs/mycert.pem" does not exist

Solution : use absolute paths in your config file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.