From 433d9d7d4afb8e8114096277ecea67ebfa2e34ea Mon Sep 17 00:00:00 2001 From: Tiexin Guo Date: Mon, 11 Nov 2024 10:03:17 +0800 Subject: [PATCH] fix: restart services failed within the okay delay period --- internals/overlord/servstate/handlers.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internals/overlord/servstate/handlers.go b/internals/overlord/servstate/handlers.go index 24172e0c..b35c7742 100644 --- a/internals/overlord/servstate/handlers.go +++ b/internals/overlord/servstate/handlers.go @@ -331,8 +331,16 @@ func (s *serviceData) start() error { if err != nil { return err } - s.transition(stateStarting) - time.AfterFunc(okayDelay, func() { logError(s.okayWaitElapsed()) }) + if s.config.Startup == plan.StartupEnabled { + // If a service is configured with `startup: enabled`, skip the stateStarting/okayDelay + // and transition it into the running state, so that even if it fails within okayDelay, + // Pebble will still restart it. + s.started <- nil + s.transition(stateRunning) + } else { + s.transition(stateStarting) + time.AfterFunc(okayDelay, func() { logError(s.okayWaitElapsed()) }) + } default: return fmt.Errorf("cannot start service while %s", s.state)