Start a Python Script in Virtual Environnment at Boot

Tested on Synology

This example is to automatically start at boot the python script created in this post

Change directory

cd /etc/systemd/system

Create the service file

sudo nano flask_test_server.service

copy & paste below

[Unit]
Description=<project flask_test_server>

[Service]
User=root
WorkingDirectory=/volume1/homes/Daniel/virtual_env_test/virtual_python
ExecStart=/volume1/homes/Daniel/virtual_env_test/virtual_python/bin/python3 flask_test.py
Restart=always

[Install]
WantedBy=multi-user.target

Reload the service files to include the new service

sudo systemctl daemon-reload

Start the service

sudo systemctl start flask_test_server.service

Check the status of the service

sudo systemctl status flask_test_server.service

check also here http://192.168.0.216:18085/

Enable the service on every reboot

sudo systemctl enable flask_test_server.service

Et voilĂ …..