How to disable a service during offline updates

My problem is sometimes my ollama.service will hang because of an intermittent Nvidia dGPU problem and therefore the offline update takes a long time just to kill that process and shut down. It’s apparent that some services like gdm (and maybe nvidia-powerd too) must be somehow prevented from running during the offline update. Is there a systemd setting I can change for any unit file that prevents it from running during the offline update reboot (dnf offline reboot)? I’m also curious how the system is able to eventually shutdown the process, since I’m unable to find a way to do it when it happens during normal system shutdowns, in which case I have to force shutdown by holding the power button. I’m happy to see this isn’t a problem during the offline update, although when it’s affected does take significantly longer. Thanks for your help.

The way systemd works is that systemd is told which target to boot, typically multi-user.target.
The target has dependent services that will be started.

In the case of offline update I think a unique target is used.
Your ollama.service should not be a dependency tree of that target.

Is the delay in shutting down, not running the offline update after the reboot?

sudo mkdir -p -Z /etc/systemd/system/ollama.service.d
sudo tee /etc/systemd/system/ollama.service.d/override.conf << EOF > /dev/null
[Install]
WantedBy=
WantedBy=graphical.target
EOF
sudo systemctl daemon-reload
sudo systemctl disable ollama.service
sudo systemctl enable ollama.service
1 Like

I think that only disables in the WantedBy= targets?

The OP would need to find where else ollama.service is mentioned.

Actually not, see: systemctl(1)

It’s default.target, which also triggers with system-update.target.

3 Likes

This looks like exactly what I asked for, thank you! I’ll just go ahead and mark this as the answer.

3 Likes