[Unit]
Description=MOMO Pro System - Gunicorn WSGI Server
After=network.target

[Service]
Type=notify
User=ogt
Group=ogt
RuntimeDirectory=gunicorn
WorkingDirectory=/home/ogt/momo_pro_system
Environment="PATH=/home/ogt/momo_pro_system/venv/bin:/usr/bin:/bin"
# V-Fix: 啟動前清理舊進程（暫時註解，改用手動清理或 deploy 腳本處理）
# ExecStartPre=/usr/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 \
          --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 \
          --max-requests 1000 \
          --max-requests-jitter 50 \
          --worker-class gthread \
          app:app
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
TimeoutStopSec=5
PrivateTmp=true
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
