Merge pull request #1963 from owncloud/fix-1616

Stop supervisor if a service fails to start
This commit is contained in:
Willy Kloucek
2021-04-26 08:33:26 +02:00
committed by GitHub
2 changed files with 23 additions and 4 deletions

View File

@@ -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

View File

@@ -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)