Logo
Michael Scheiwiller
Published on

Fast Private Streamlit Sharing with Systemd

Authors
  • avatar
    Name
    Michael Scheiwiller
    Twitter

This is a follow up to Legal RAG with Streamlit, ChromaDB and OpenAI

If you want to share a Streamlit app with someone who is not technical and can not clone and build the app on their own, you have to provide them somehow with a link they can access to use the app and give you feedback. For Streamlit apps whichs repos are public, this is easily done with Streamlit Cloud.

But if you want to keep the repo private, you have to host the app somewhere. One of the easiest ways to do this i found to use a VPS and run the app as a systemd service (check this post for a vps setup guide). This post details how i set it up.

Running as a systemd Service

To keep the Streamlit app running in the background and automatically restart it if it fails, you can set it up as a systemd service.

  1. Create the service file directly in /etc/systemd/system:
sudo vim /etc/systemd/system/streamlit.service
  1. Paste the following content (edit paths as needed):
[Unit]
Description=Streamlit App
After=network.target

[Service]
User=devuser
WorkingDirectory=/home/devuser/projects/test-rag
ExecStart=/home/devuser/projects/test-rag/.venv/bin/streamlit run app.py --server.port 8501 --server.address 0.0.0.0
Restart=always

[Install]
WantedBy=multi-user.target
  1. Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable streamlit
sudo systemctl start streamlit
  1. Check the status:
sudo systemctl status streamlit

The app will now run in the background and restart automatically if it crashes. You can access it at http://YOUR_VPS_IP:8501/.

Want to build something similar for your team or business? Contact me