[Unit] Description=Momo Pro System - Flask Application After=network.target [Service] Type=simple User=ogt WorkingDirectory=/home/ogt/momo_pro_system Environment="PATH=/home/ogt/momo_pro_system/venv/bin" # V-Fix: 啟動前確保清理所有舊的 gunicorn 進程 ExecStartPre=/bin/bash /home/ogt/momo_pro_system/kill_old_gunicorn.sh ExecStart=/home/ogt/momo_pro_system/venv/bin/gunicorn \ --workers 4 \ --threads 2 \ --timeout 120 \ --graceful-timeout 30 \ --bind 127.0.0.1:5000 \ --access-logfile /home/ogt/momo_pro_system/logs/gunicorn-access.log \ --error-logfile /home/ogt/momo_pro_system/logs/gunicorn-error.log \ --log-level info \ app:app Restart=always RestartSec=10 StandardOutput=journal StandardError=journal # V-Fix: 優雅關閉設定,避免端口佔用問題 KillMode=mixed KillSignal=SIGTERM TimeoutStopSec=60 SendSIGKILL=yes [Install] WantedBy=multi-user.target