Skip to content

Run JupyterHub as a system service

Running JupyerHub as a system service allows JupyterHub to run continously even if we aren't logged into the server. It also keeps JupyterHub running while when we log into the server and make any changes.

To run JupyterHub as a system service (according to this wiki ), we need to create a service file in the /etc/systemd/system directory. cd into the directory and have a look around. We see a couple files that end in .service

$ cd /etc/systemd/system
$ ls      
dbus-org.freedesktop.thermald.service                              sshd.service                            syslog.service

Create a new .service file called jupyterhub.service

$ sudo nano jupyterhub.service

In the file, add the following. Note that as part of the PATH environment variable /opt/miniconda3/envs/jupyterhubenv/bin/ is included. This is the path to our virtual environment. As part of the ExecStart= section, we include a flag for our JupyterHub config file located at /etc/jupyterhub/ file.


ExecStart=/opt/miniconda3/envs/jupyterhubenv/bin/jupyterhub -f /etc/jupyterhub/


Save and exit the nano text editor with [Ctrl-x] + [Enter].

Now we need to reload the system daemon and run JupyterHub as a system service using the command: sudo systemctl <start|stop|status> jupyterhub

$ sudo systemctl daemon-reload
$ sudo systemctl start jupyterhub

We can see if JupyterHub is running with:

$ sudo systemctl status jupyterhub

 Loaded: loaded (/etc/systemd/system/jupyterhub.service; 
 Active: active (running)

Test local OAuth

Now we can go to the server and log in as our non-root user peter.

JupyterHub PAM Login

A couple times I thought that JupyterHub was running after using systemctl start jupyterhub, but the JupyterHub wasn't working when I went to the server's web address. It turned out that JupyterHub wasn't running when I keyed in systemctl status jupyterhub. Most times looking for an error and tracking down the the error worked, but one time it seemed to be a problem with the http-configurable-proxy.

The following command will shut down the proxy if you get stuck like I did (insert the number corresponding to the configurable-http-proxy process after the kill command):

$ ps aux | grep configurable-http-proxy
$ kill #### 

Next Steps

The next step is to have JupyterHub accept GitHub usernames and passwords. This will allow students with Github accounts to log into JupyterHub and means we don't have to deal with creating new users and sending students usernames and passwords.