Listen and wait for errors when server exits
This commit is contained in:
parent
010d0ffe4b
commit
fa714c1bdd
4 changed files with 33 additions and 12 deletions
21
cli/start.go
21
cli/start.go
|
@ -56,11 +56,24 @@ var startCmd = &cobra.Command{
|
||||||
return
|
return
|
||||||
|
|
||||||
},
|
},
|
||||||
PostRun: func(cmd *cobra.Command, args []string) {
|
PostRunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
|
||||||
tcp.Exit()
|
if err = web.Exit(); err != nil {
|
||||||
web.Exit()
|
log.Fatal(err)
|
||||||
db.Exit()
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = tcp.Exit(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = db.Exit(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
7
db/db.go
7
db/db.go
|
@ -60,12 +60,9 @@ func Setup(opts *cnf.Options) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit shuts down the connection with the data layer
|
// Exit shuts down the connection with the data layer
|
||||||
func Exit() {
|
func Exit() error {
|
||||||
|
|
||||||
log.WithPrefix("db").Infof("Gracefully shutting down database")
|
log.WithPrefix("db").Infof("Gracefully shutting down database")
|
||||||
|
return db.Close()
|
||||||
db.Close()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import loads database operations from a reader.
|
// Import loads database operations from a reader.
|
||||||
|
|
11
tcp/tcp.go
11
tcp/tcp.go
|
@ -27,6 +27,13 @@ import (
|
||||||
|
|
||||||
var srf *serf.Serf
|
var srf *serf.Serf
|
||||||
|
|
||||||
|
var listeners []*listener
|
||||||
|
|
||||||
|
type listener struct {
|
||||||
|
name string
|
||||||
|
call func([]byte)
|
||||||
|
}
|
||||||
|
|
||||||
// Setup sets up the server for remote connections
|
// Setup sets up the server for remote connections
|
||||||
func Setup(opts *cnf.Options) (err error) {
|
func Setup(opts *cnf.Options) (err error) {
|
||||||
|
|
||||||
|
@ -100,7 +107,7 @@ func Send(name string, data []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit tears down the server gracefully
|
// Exit tears down the server gracefully
|
||||||
func Exit() {
|
func Exit() (err error) {
|
||||||
log.WithPrefix("tcp").Infof("Gracefully shutting down %s protocol", "tcp")
|
log.WithPrefix("tcp").Infof("Gracefully shutting down %s protocol", "tcp")
|
||||||
srf.Leave()
|
return srf.Leave()
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,10 @@ func Setup(opts *cnf.Options) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit tears down the server gracefully
|
// Exit tears down the server gracefully
|
||||||
func Exit() {
|
func Exit() (err error) {
|
||||||
|
|
||||||
log.WithPrefix("web").Infof("Gracefully shutting down %s protocol", "web")
|
log.WithPrefix("web").Infof("Gracefully shutting down %s protocol", "web")
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue