用于自动启动 Streamlit 应用程序的 Systemd 服务文件
以下 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 myappIf this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow