[Unit]
Description=Companion AI API Service
Documentation=https://github.com/santhoshjan/companion
After=network.target ollama.service
Wants=ollama.service

[Service]
Type=simple
User=companion
Group=companion
WorkingDirectory=/opt/companion
Environment=PYTHONPATH=/opt/companion
Environment=COMPANION_CONFIG=/opt/companion/config.json
Environment=COMPANION_DATA_DIR=/var/lib/companion

# Start the API server
ExecStart=/opt/companion/venv/bin/python -m uvicorn companion.api:app --host 0.0.0.0 --port 7373

# Restart on failure
Restart=on-failure
RestartSec=5

# Resource limits
MemoryMax=2G
CPUQuota=200%

# Security hardening
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/var/lib/companion

[Install]
WantedBy=multi-user.target
