ComputerBas

Tips, tricks and manuals

Je bent niet ingelogd.

#1 2022-01-23 22:42:36

Bas
Administrator
Geregistreerd: 2019-11-10
Posts: 93

How to autostart a Python app as a service and restart on failure?

In console as root:

nano /lib/systemd/system/yourapp.service
[Unit]
Description=yourapp Service
After=multi-user.target
Conflicts=getty@tty1.service

[Service]
Type=simple
ExecStart=/usr/bin/python3 /path/to/your/app.py
StandardInput=tty-force
Restart=on-failure

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable yourapp.service
systemctl start yourapp.service
systemctl status yourapp.service
systemctl stop yourapp.service 
systemctl start yourapp.service 
systemctl status yourapp.service
systemctl restart yourapp.service

Mocht de app niet goed starten of als je de app wil starten vanaf de commandprompt dan kan je ook een apploop.sh maken.

nano apploop.sh
while true
do
    python3 yourapp.py
done

Maak apploop.sh als programma uitvoerbaar en start de loop:

./apploop.sh

Offline

Forum footer

Powered by FluxBB 1.5.11