Exit the node if the http server errors

This commit is contained in:
StephenButtolph 2020-05-13 00:51:30 -04:00
parent 19db6fe6d5
commit 4497839c2c
1 changed files with 17 additions and 15 deletions

View File

@ -479,18 +479,19 @@ func (n *Node) initAPIServer() {
n.APIServer.Initialize(n.Log, n.LogFactory, n.Config.HTTPPort) n.APIServer.Initialize(n.Log, n.LogFactory, n.Config.HTTPPort)
if n.Config.EnableHTTPS { go n.Log.RecoverAndPanic(func() {
n.Log.Debug("Initializing API server with TLS Enabled") if n.Config.EnableHTTPS {
go n.Log.RecoverAndPanic(func() { n.Log.Debug("Initializing API server with TLS Enabled")
if err := n.APIServer.DispatchTLS(n.Config.HTTPSCertFile, n.Config.HTTPSKeyFile); err != nil { err := n.APIServer.DispatchTLS(n.Config.HTTPSCertFile, n.Config.HTTPSKeyFile)
n.Log.Warn("API server initialization failed with %s, attempting to create insecure API server", err) n.Log.Warn("Secure API server initialization failed with %s, attempting to create insecure API server", err)
n.APIServer.Dispatch() }
}
}) n.Log.Debug("Initializing API server")
} else { err := n.APIServer.Dispatch()
n.Log.Debug("Initializing API server with TLS Disabled")
go n.Log.RecoverAndPanic(func() { n.APIServer.Dispatch() }) n.Log.Fatal("API server initialization failed with %s", err)
} n.TCall.AsyncCall(salticidae.ThreadCallCallback(C.onTerm), nil)
})
} }
// Assumes n.DB, n.vdrs all initialized (non-nil) // Assumes n.DB, n.vdrs all initialized (non-nil)
@ -623,15 +624,16 @@ func (n *Node) Initialize(Config *Config, logger logging.Logger, logFactory logg
// initialize shared memory // initialize shared memory
n.initSharedMemory() n.initSharedMemory()
if err = n.initNetlib(); err != nil { // Set up all networking
return fmt.Errorf("problem initializing networking: %w", err)
}
// Start HTTP APIs // Start HTTP APIs
n.initAPIServer() // Start the API Server n.initAPIServer() // Start the API Server
n.initKeystoreAPI() // Start the Keystore API n.initKeystoreAPI() // Start the Keystore API
n.initMetricsAPI() // Start the Metrics API n.initMetricsAPI() // Start the Metrics API
// Start node-to-node consensus server // Start node-to-node consensus server
if err = n.initNetlib(); err != nil { // Set up all networking
return fmt.Errorf("problem initializing networking: %w", err)
}
if err := n.initValidatorNet(); err != nil { // Set up the validator handshake + authentication if err := n.initValidatorNet(); err != nil { // Set up the validator handshake + authentication
return fmt.Errorf("problem initializing validator network: %w", err) return fmt.Errorf("problem initializing validator network: %w", err)
} }