Systemd service file for autostarting Streamlit application

The following systemd service file is used to run a streamlit application. It assumes that the streamlit application is located at /home/user/myapp/app.py and that the streamlit application should be run as the user user.

Install streamlit using sudo pip install -U streamlit

Save it in e.g. /etc/systemd/system/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

Adjust server.address and server.port to your needs.

Then, enable and start the service:

sudo systemctl enable --now myapp