Auto Start Jupyter Lab on Machine Boot Up

In the previous article , we have seen how to install jupyter lab on a virtual machine in Google Cloud Platform. In this article, we will see , how we can enable the jupyter lab as a service so that a user doesn’t have to run the command manually to start the jupyter lab service.
Login to the Virtual Machine via SSH and execute the below commands:
sudo mkdir -p /opt/jupyterlab/etc/systemd
sudo touch /opt/jupyterlab/etc/systemd/jupyterlab.service
Open the file “/opt/jupyterlab/etc/systemd/jupyterlab.service” and add below content
[Unit]
Description=JupyterLab
After=syslog.target network.target[Service]
User=root
Environment="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/puppetlabs/bin"
ExecStart=/usr/local/bin/jupyter lab --ip 0.0.0.0 --port 8888 --no-browser --allow-root[Install]
WantedBy=multi-user.target
Please validate the text that is in bold and ensure that its replaced with the correct path based on your environments.
Save the file and execute below commands.
sudo ln -s /opt/jupyterlab/etc/systemd/jupyterlab.service /etc/systemd/system/jupyterlab.service
sudo systemctl daemon-reload
sudo systemctl enable jupyterlab.service
sudo systemctl start jupyterlab.service
sudo systemctl status jupyterlab.service
You will observe a token when you run the last command.
Visit the URL “http://<<IP>>:8888” and set the token retrieved from above step and provide your password so that we don’t need token every-time.
Now stop the VM and start it again. Once the VM is started , visit “http://<<IP>>:8888” and it will ask for password to proceed.