stop supervisor if a service fails to start

This commit is contained in:
A.Unger
2021-04-23 14:13:58 +02:00
parent fd01ee4dd0
commit 11c11b06dc

View File

@@ -123,6 +123,10 @@ 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
@@ -131,6 +135,9 @@ func Start(o ...Option) error {
// 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.EventTypeServiceTerminate {
halt <- os.Interrupt
}
s.Log.Info().Str("event", e.String()).Msg(fmt.Sprintf("supervisor: %v", e.Map()["supervisor_name"]))
},
})
@@ -148,10 +155,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)