diff --git a/cli/start.go b/cli/start.go index a84b7c56..799650a9 100644 --- a/cli/start.go +++ b/cli/start.go @@ -56,11 +56,24 @@ var startCmd = &cobra.Command{ return }, - PostRun: func(cmd *cobra.Command, args []string) { + PostRunE: func(cmd *cobra.Command, args []string) (err error) { - tcp.Exit() - web.Exit() - db.Exit() + if err = web.Exit(); err != nil { + log.Fatal(err) + return + } + + if err = tcp.Exit(); err != nil { + log.Fatal(err) + return + } + + if err = db.Exit(); err != nil { + log.Fatal(err) + return + } + + return }, } diff --git a/db/db.go b/db/db.go index 53d57233..df266df6 100644 --- a/db/db.go +++ b/db/db.go @@ -60,12 +60,9 @@ func Setup(opts *cnf.Options) (err error) { } // Exit shuts down the connection with the data layer -func Exit() { - +func Exit() error { log.WithPrefix("db").Infof("Gracefully shutting down database") - - db.Close() - + return db.Close() } // Import loads database operations from a reader. diff --git a/tcp/tcp.go b/tcp/tcp.go index 577df72a..0f1cf3e0 100644 --- a/tcp/tcp.go +++ b/tcp/tcp.go @@ -27,6 +27,13 @@ import ( var srf *serf.Serf +var listeners []*listener + +type listener struct { + name string + call func([]byte) +} + // Setup sets up the server for remote connections func Setup(opts *cnf.Options) (err error) { @@ -100,7 +107,7 @@ func Send(name string, data []byte) { } // Exit tears down the server gracefully -func Exit() { +func Exit() (err error) { log.WithPrefix("tcp").Infof("Gracefully shutting down %s protocol", "tcp") - srf.Leave() + return srf.Leave() } diff --git a/web/web.go b/web/web.go index 7b00b2fe..af831813 100644 --- a/web/web.go +++ b/web/web.go @@ -80,6 +80,10 @@ func Setup(opts *cnf.Options) (err error) { } // Exit tears down the server gracefully -func Exit() { +func Exit() (err error) { + log.WithPrefix("web").Infof("Gracefully shutting down %s protocol", "web") + + return + }