Running a Python app with python app.py in a terminal stops the moment you disconnect. systemd keeps it running reliably, restarts it if it crashes, and starts it at boot.

Create a service unit

Write /etc/systemd/system/myapp.service:

[Unit]
Description=My Python app
After=network.target

[Service]
User=www-data
WorkingDirectory=/var/www/myapp
ExecStart=/var/www/myapp/venv/bin/gunicorn myapp:app --bind 127.0.0.1:8000
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Enable and manage it

sudo systemctl daemon-reload
sudo systemctl enable --now myapp
sudo systemctl status myapp
journalctl -u myapp -f     # live logs

Why this beats nohup/screen

systemd restarts your app automatically after a crash or reboot, captures logs in the journal, and manages start-up order. It's the standard, production-grade way to run any long-lived process on Linux.