[Unit]
Description=Speaches container service
Wants=network-online.target
After=network-online.target docker.service
Requires=docker.service

[Service]
Type=simple
ExecStartPre=/usr/bin/docker volume create {{ speaches_volume_name }}
ExecStartPre=-/usr/bin/docker rm --force {{ speaches_container_name }}
ExecStart=/usr/bin/docker run \
  --name={{ speaches_container_name }} \
  --publish=0.0.0.0:{{ speaches_port }}:8000 \
  --volume={{ speaches_volume_name }}:{{ speaches_volume_mount }} \
  --gpus {{ speaches_gpu_devices }} \
  --detach=false \
  --env=HF_TOKEN={{ speaches_hugging_face_hub_token }} \
  --env=PRELOAD_MODELS='{{ speaches_preload_models | to_json }}' \
  {{ speaches_docker_image }}
ExecStop=/usr/bin/docker stop {{ speaches_container_name }}
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
