建立 systemd 服務檔案 /etc/systemd/system/my_web.service
:
[Unit]
Description=My Web Application
After=network.target
[Service]
Type=simple
User=your_username
WorkingDirectory=/path/to/my_web
Environment=PATH=/path/to/my_web/venv/bin
ExecStart=/path/to/my_web/venv/bin/python app.py
Restart=always
[Install]
WantedBy=multi-user.target
啟用服務:
sudo systemctl daemon-reload
sudo systemctl enable my_web.service
sudo systemctl start my_web.service
安全性: 此範例為演示用途,生產環境需要增加安全措施
錯誤處理: 需要增加更完善的錯誤處理和重試機制
沒有留言:
張貼留言