[Unit]
Description=IDS ML Backend (FastAPI)
After=network.target postgresql-16.service
Wants=postgresql-16.service

[Service]
Type=simple
User=ids
Group=ids
WorkingDirectory=/opt/ids/python_ml
EnvironmentFile=/opt/ids/.env

# Comando esecuzione (usa virtual environment)
ExecStart=/opt/ids/python_ml/venv/bin/python3 main.py

# Restart automatico sempre (non solo on-failure)
Restart=always
RestartSec=10
StartLimitInterval=300
StartLimitBurst=5

# Limiti risorse
LimitNOFILE=65536
MemoryMax=2G

# Logging
StandardOutput=append:/var/log/ids/ml_backend.log
StandardError=append:/var/log/ids/ml_backend.log
SyslogIdentifier=ids-ml-backend

[Install]
WantedBy=multi-user.target
