Przejdź do treści

Linux – Usługi – Procesy – Tworzenie usługi

Create a file named your-service.service and include the following:

[Unit]
Description=<description about this service>

[Service]
User=<user e.g. root>
WorkingDirectory=<directory_of_script e.g. /root>
ExecStart=<script which needs to be executed>
Restart=always

[Install]
WantedBy=multi-user.target

Example

[Unit]
Description=<project description>

[Service]
User=<user e.g. root>
WorkingDirectory=<path to your project directory>
ExecStart=/bin/bash -c 'cd /home/ubuntu/project/ && source venv/bin/activate && python test.py'

[Install]
WantedBy=multi-user.target

Reload the service files to include the new service.

sudo systemctl daemon-reload

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Wymagane pola są oznaczone *