以下 systemd 服务文件用于运行 streamlit 应用程序。它假设 streamlit 应用程序位于 /home/user/myapp/app.py,并且 streamlit 应用程序应以用户 user 运行。
使用 pip install -U streamlit 安装 streamlit
将其保存在例如 /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根据需要调整 server.address 和 server.port。
然后,启用并启动服务:
enable-myapp.sh
sudo systemctl enable --now myapp如果这篇文章对您有帮助,请考虑请我喝杯咖啡或通过 PayPal 捐款,以支持 TechOverflow 上新文章的研究与发布