diff --git a/changelog/unreleased/stop-supervisor-if-failure.md b/changelog/unreleased/stop-supervisor-if-failure.md new file mode 100644 index 0000000000..8bccf7a53d --- /dev/null +++ b/changelog/unreleased/stop-supervisor-if-failure.md @@ -0,0 +1,7 @@ +Bugfix: Stop the supervisor if a service fails to start + +Steps to make the supervisor fail: + +`PROXY_HTTP_ADDR=0.0.0.0:9144 bin/ocis server` + +https://github.com/owncloud/ocis/pull/1963 diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index cfab669058..268d7473fd 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -123,16 +123,32 @@ func Start(o ...Option) error { return err } + // halt listens for interrupt signals and blocks. + halt := make(chan os.Signal, 1) + signal.Notify(halt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) + // notify goroutines that they are running on supervised mode s.cfg.Mode = ociscfg.SUPERVISED setMicroLogger() + // tolerance controls backoff cycles from the supervisor. + tolerance := 5 + totalBackoff := 0 + // Start creates its own supervisor. Running services under `ocis server` will create its own supervision tree. s.Supervisor = suture.New("ocis", suture.Spec{ EventHook: func(e suture.Event) { + if e.Type() == suture.EventTypeBackoff { + totalBackoff++ + if totalBackoff == tolerance { + halt <- os.Interrupt + } + } s.Log.Info().Str("event", e.String()).Msg(fmt.Sprintf("supervisor: %v", e.Map()["supervisor_name"])) }, + FailureThreshold: 5, + FailureBackoff: 3 * time.Second, }) // reva storages have their own logging. For consistency sake the top level logging will cascade to reva. @@ -148,10 +164,6 @@ func Start(o ...Option) error { } rpc.HandleHTTP() - // halt listens for interrupt signals and blocks. - halt := make(chan os.Signal, 1) - signal.Notify(halt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) - l, err := net.Listen("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)) if err != nil { s.Log.Fatal().Err(err)