Need to know for any modern linux system administrator
Why systemd? Well systemd is pretty cool in the fact that we can create either system or user services that will start at bootup or login respectively and restart themselves if they fail. Before systemd services I was using a lot more cron jobs which can be cool, but can also be a pain to manage! Below I will show you how to create two simple services that will handle one of my juypyter notebook and lab environments.
pi@pi4b:~ $ sudo nano ~/jupyter-notebook.service
# Jupyter-Notebook Service File [Unit] Description=Jupyter Notebook After=network.target [Service] Type=simple User=pi WorkingDirectory=/home/pi ExecStart=/home/pi/.local/bin/jupyter-notebook --port=8888 Restart=on-failure [Install] WantedBy=multi-user.target
pi@pi4b:~ $ sudo nano ~/jupyter-lab.service
# Jupyter-Lab Service File [Unit] Description=Jupyter Lab After=network.target [Service] Type=simple User=pi WorkingDirectory=/home/pi ExecStart=/home/pi/.local/bin/jupyter-lab --port=8889 Restart=on-failure [Install] WantedBy=multi-user.target
pi@pi4b:~ $ sudo systemctl enable ~/jupyter-notebook.service
Created symlink /etc/systemd/system/multi-user.target.wants/jupyter-notebook.service → /home/pi/jupyter-notebook.service. Created symlink /etc/systemd/system/jupyter-notebook.service → /home/pi/jupyter-notebook.service.
pi@pi4b:~ $ sudo systemctl enable ~/jupyter-lab.service
Created symlink /etc/systemd/system/multi-user.target.wants/jupyter-lab.service → /home/pi/jupyter-lab.service. Created symlink /etc/systemd/system/jupyter-lab.service → /home/pi/jupyter-lab.service.
pi@pi4b:~ $ sudo systemctl daemon-reload
pi@pi4b:~ $ sudo systemctl start juptyer-notebook.service
pi@pi4b:~ $ sudo systemctl start juptyer-lab.service
pi@pi4b:~ $ sudo systemctl status jupyter-notebook.service
● jupyter-notebook.service - Jupyter Notebook Loaded: loaded (/home/pi/jupyter-notebook.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2020-05-28 02:24:24 EDT; 1h 12min ago Main PID: 498 (jupyter-noteboo) Tasks: 12 (limit: 4915) CGroup: /system.slice/jupyter-notebook.service ├─ 498 /usr/bin/python3 /home/pi/.local/bin/jupyter-notebook --port=8888 └─1612 /usr/bin/python3 -m ipykernel_launcher -f /home/pi/.local/share/jupyter/runtime/kernel-392b8244-7f07-47e0-a0bc-2c34c999
pi@pi4b:~ $ sudo systemctl status jupyter-lab.service
● jupyter-lab.service - Jupyter Lab Loaded: loaded (/home/pi/jupyter-lab.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2020-05-28 02:24:24 EDT; 1h 4min ago Main PID: 500 (jupyter-lab) Tasks: 14 (limit: 4915) CGroup: /system.slice/jupyter-lab.service ├─ 500 /usr/bin/python3 /home/pi/.local/bin/jupyter-lab --port=8889 └─1368 /usr/bin/python3 -m ipykernel_launcher -f /home/pi/.local/share/jupyter/runtime/kernel-e469053f-cc99-4426-ae79-3a772ae1