System Service & DB

GSOC Week 4@SCoRe Lab

Dhruvi Doshi
SCoRe Lab
2 min readJul 13, 2022

--

Photo by Alfons Morales on Unsplash

We use SQLite for data persistence here. We need the list of registered probes to accept data from valid users and trace the health of each of them. SQLite is pretty easy to use with python3. It comes bundled with python3 so we don’t need to install any separate packages.

Standard SQL queries work with SQLite too. Quoting resources that I refer to for using SQLite in python:

  1. https://medium.com/analytics-vidhya/programming-with-databases-in-python-using-sqlite-4cecbef51ab9
  2. https://towardsdatascience.com/python-sqlite-tutorial-the-ultimate-guide-fdcb8d7a4f30

& the official docs of course.

Whenever I receive a new request from the probe to connect, I have to save its details in my server’s registry. The fields that I would require for the probe are hostname, registered time, last active time, current status and last time when data was sent.

Then, I was required to run the server as the system service. You might have already guessed it what I might have used: Systemd

Creating services is a good thing when you need to run a certain application every time your linux computer boot for example. Basically, Systemd is an init system. We do have some other init systems like SystemV. There are plenty of resources out on the internet. Please allow me to help you out with a few I like:

  1. https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6
  2. https://www.golinuxcloud.com/beginners-guide-systemd-tutorial-linux/
  3. https://medium.com/the-code-vault/systemd-simple-service-examples-ce586afeed27
  4. https://medium.com/@vinicenter/creating-a-service-in-linux-using-systemd-f2ded253cd92
  5. http://0pointer.de/blog/projects/systemd.html

Just to refresh your memory, I would like to re-iterate through the difference between BASH & SH.

BASH is Bourne Again SHell. It is the superset of SH & BASH is a lil more powerful than SH. BASH supports more commands. A very significant example is source. source is a command implemented in bash, but not in sh. { Source, as in, source venv/bin/activate }

This is a trivial pointer rather but might save you sometimes :)

Thank you for reading it all.

Happy Coding!! BR!!

--

--