[Unit]
Description=LM Studio Server
After=network.target
Wants=network.target

[Service]
Type=simple
User={{ lm_studio_user }}
Group={{ lm_studio_user }}

# Répertoire home pour que lms trouve ses fichiers
Environment=HOME={{ lm_studio_home }}

# ROCm — obligatoire pour RX 6700XT (gfx1031 non officiel)
Environment=HSA_OVERRIDE_GFX_VERSION={{ hsa_override_gfx_version }}

# PATH inclut le binaire lms
Environment=PATH={{ lm_studio_home }}/.lmstudio/bin:/usr/local/bin:/usr/bin:/bin

Environment=LMS_PORT={{ lm_studio_port }}
Environment=LMS_BIND={{ lm_studio_host }}
Environment=LMS_MODEL={{ lm_studio_default_model }}
Environment=LMS_CONTEXT_LENGTH={{ lm_studio_context_length }}
Environment=LMS_GPU_OFFLOAD={{ lm_studio_gpu_offload }}

# Wrapper: runs lms server start, auto-loads model if LMS_MODEL is set, then monitors llmster
ExecStart=/opt/lmstudio/run-llmster.sh

Restart=on-failure
RestartSec=15
TimeoutStartSec=120

# Journalisation
StandardOutput=journal
StandardError=journal
SyslogIdentifier=lm-studio

[Install]
WantedBy=multi-user.target
