Fichier de service Systemd pour le démarrage automatique d'une application Streamlit

Le fichier de service systemd suivant est utilisé pour exécuter une application streamlit. Il suppose que l’application streamlit est située à /home/user/myapp/app.py et que l’application streamlit doit être exécutée en tant qu’utilisateur user.

Installez streamlit en utilisant pip install -U streamlit

Enregistrez-le par exemple dans /etc/systemd/system/myapp.service :

myapp.service
[Unit]
Description=My streamlit app

[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/opt/myapp
ExecStart=/usr/local/bin/streamlit run myapp.py --server.address 127.0.0.1 --server.port 18215
Restart=always
RestartSec=10s

[Install]
WantedBy=multi-user.target

Ajustez server.address et server.port selon vos besoins.

Ensuite, activez et démarrez le service :

enable-myapp.sh
sudo systemctl enable --now myapp

Check out similar posts by category: Python, Streamlit, Systemd