Zuerst erstelle eine Systemd Konfigurationsdatei für den Service.
sudo nano /etc/systemd/system/flask-certbot.service
und füge das ein
[Unit]
Description=Flask Certbot Web Interface
After=network.target
[Service]
User=dein-benutzername
WorkingDirectory=/pfad/zum/flask-app
ExecStart=/usr/bin/python3 /pfad/zum/flask-app/app.py
Restart=always
Environment=PATH=/pfad/zum/python3-env/bin:/usr/bin:/bin
Environment=FLASK_APP=app.py
Environment=FLASK_ENV=production
[Install]
WantedBy=multi-user.target
Das Service starten und mit Autostart einrichten kannst du mit systemctl.
sudo systemctl daemon-reload
sudo systemctl enable flask-certbot.service
sudo systemctl start flask-certbot.service