Automagically Start Jupyterlab
This is for all you data scientists and ai lovers out there! What if your Jupyter Lab can quietly start behind the scene everytime you start your computer, won’t that be great?
Yes, you can automatically start your jupyterlab everytime you boot into your system. It’s not a dream! With what we learned from Linux service, it is quite easy to do that. But first you will need to install jupyterlab on your system.
Installation
If you already have jupyterlab installed on your machine, feel free to skip this section. Otherwise, I would recommend using nix to install micromamba, and use micromamba to install jupyterlab.
Let’s install nix and micormamba.
1
2
3
4
# Installing nix
ansible-pull -U https://github.com/brucechanjianle/ansible --ask-become-pass --tags nix
# Installing latest micromamba from nix store (for user)
nix-env -Ai nixpkgs.micromamba
And now, you can install jupyterlab with the following command:
1
micromamba create -n jupyterlab jupyterlab -c conda-forge
Setup Linux Service
You will need to create the respective directories for user level service, meaning these services will only start when user is ready.
Create Directories
1
mkdir ~/.config/systemd/user/ -p
Add Service File
1
2
# You can use nano if vim is not something you are familiar with.
vim ~/.config/systemd/user/jupyter_notebook.service
Paste the following content:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=Jupyter Lab Server
After=network.target
[Service]
ExecStart=/home/developer/.nix-profile/bin/micromamba run -n jupyterlab jupyter lab --port 7777 --no-browser
WorkingDirectory=%h/Documents
# Restart=on-failure
Environment=RORT=7777
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=default.target
Here, I set jupyterlab to start from the documents directory, if you want it to start from somewhere else, please change it by all means. I used port 7777 so that if you start your own jupyterlab it will be able to use the default 8888 port. Anyways, we still got a few steps left, let’s continue on.
Reload User Level Service
1
systemctl --user daemon-reload
Enable Jupyterlab Service
1
systemctl --user enable jupyter_notebook.service
Start The Service
Well, you will only need to do this once, since it has been enabled to start this service after reboot.
1
systemctl --user start jupyter_notebook.service
All Done
To validate whether the service has been run succesfully, you can run:
1
systemctl --user status jupyter_notebook.service
Well, congratulations! You made it to the end of the article, hopefully it was a helpful journey. And this is a super fast way to start your service instead of doing it at the sudo level like some other articles suggested. Until next time, keep growing!