Ollama and suspend on nvidia

Hello I was happy to find new action in ujust, the ollama. This action install a user SystemD service for podman container with latest Ollama image with choice ROMc/CUDA on device with both AMD an Nvidia GPUs.
Choosing CUDA causes a problem with suspend on my device (a laptop with Nvidia GPU). The nvidia-suspend.service fails and causes various problems. This problem seems to be tracked in this issue:
https://github.com/ollama/ollama/issues/3489
For the time being I was able to mittigate the issue by creating a system service (in /etc/systemd/system) which on suspend stops the ollama.service and starts it again on resume.

[Unit]
Before=nvidia-suspend.service
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=-/bin/systemctl --user -M OllamaUser@ stop ollama.service
ExecStop=-/bin/systemctl --user -M OllamaUser@ start ollama.service
[Install]
WantedBy=sleep.target

Thanks in advance for any better solutions.

2 Likes