How to create and configure linux service

How to create and configure linux service

In the previous post, we wrote an HTTP server script that has one drawback – it doesn’t start automatically and doesn’t work as a service.

Here are the steps to configure it as a service in Linux.

  • Script: We already have a startup script named web-server.py. Save it in the directory where it will be permanently stored. I pasted it in the path /root.
  • Execution permissions: In the previous post, we already granted execution permissions, but it’s worth mentioning here as well::
  • Initialization script: Debian uses systemd. So, go to the /etc/systemd/system/ directory and create a file named web-server.service. You can choose a different name for your service 🙂 An example configuration is provided below
  • Starting the service: After creating the service, you need to start the script and add it to the systemd system.

After completing these steps, your Python-based server should start automatically upon machine restart.

Komentarze

Nie ma jeszcze komentarzy. Może zaczniesz dyskusję?

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *