move controller signal handler to cmd
@@ -25,6 +25,9 @@ import (
"github.com/openziti/ziti/common/version"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
+ "os"
+ "os/signal"
+ "syscall"
)
func init() {
@@ -54,28 +57,39 @@ func run(cmd *cobra.Command, args []string) {
}
}
- var c *controller.Controller
- if c, err = controller.NewController(config, version.GetCmdBuildInfo()); err != nil {
+ var fabricController *controller.Controller
+ if fabricController, err = controller.NewController(config, version.GetCmdBuildInfo()); err != nil {
fmt.Printf("unable to create fabric controller %+v\n", err)
panic(err)
}
- ec, err := server.NewController(config)
+ edgeController, err := server.NewController(config)
if err != nil {
panic(err)
}
- ec.SetHostController(c)
- ec.Initialize()
-
- go ec.RunAndWait()
-
- if err = c.Run(); err != nil {
+ edgeController.SetHostController(fabricController)
+ edgeController.Initialize()
+ go waitForShutdown(fabricController, edgeController)
+ go edgeController.Run()
+ if err := fabricController.Run(); err != nil {
panic(err)
}
+
} else {
panic(err)
}
}
+
+func waitForShutdown(fabricController *controller.Controller, edgeController *server.Controller) {
+ ch := make(chan os.Signal, 1)
+ signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
+
+ <-ch
+
+ pfxlog.Logger().Info("shutting down ziti-controller")
+ edgeController.Shutdown()
+ fabricController.Shutdown()
+}
