From 7ea9a0daea14a922bd9e219098252b67b1b782a8 Mon Sep 17 00:00:00 2001 From: Predrag Rogic Date: Sat, 6 Jan 2024 17:58:09 +0000 Subject: [PATCH] fix "Failed to enable container runtime: sudo systemctl restart cri-docker" --- pkg/minikube/cruntime/docker.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/pkg/minikube/cruntime/docker.go b/pkg/minikube/cruntime/docker.go index c4cbead626..61cc6066d5 100644 --- a/pkg/minikube/cruntime/docker.go +++ b/pkg/minikube/cruntime/docker.go @@ -171,21 +171,35 @@ func (r *Docker) Enable(disOthers bool, cgroupDriver string, inUserNamespace boo return err } + // restart cri-docker + // avoid error: "Exiting due to RUNTIME_ENABLE: Failed to enable container runtime: sudo systemctl restart cri-docker: exit status 1" + // => journalctl: "cri-docker.socket: Socket service cri-docker.service already active, refusing." if r.CRIService != "" { - if err := r.Init.Enable("cri-docker.socket"); err != nil { + socket := "cri-docker.socket" + service := "cri-docker.service" + // allow "native" socket activation: + // prevent active socket to reactivate service, that we're going to stop next - 'systemctl status cri-docker.socket': "Triggers: cri-docker.service" + // intentionally continue on any error + if r.Init.Active(socket) { + _ = r.Init.Stop(socket) + } + if r.Init.Active(service) { + _ = r.Init.Stop(service) + } + + if err := r.Init.Unmask(socket); err != nil { return err } - if err := r.Init.Unmask(r.CRIService); err != nil { + if err := r.Init.Enable(socket); err != nil { return err } - if err := r.Init.Enable(r.CRIService); err != nil { + if err := r.Init.Restart(socket); err != nil { return err } - if err := r.Init.Restart(r.CRIService); err != nil { - return err - } - if err := r.Init.Restart("cri-docker"); err != nil { - return err + + // try to restart service if stopped, intentionally continue on any error + if !r.Init.Active(service) { + _ = r.Init.Restart(service) } }