Handle run errors

This commit is contained in:
Tyler Treat
2017-06-23 13:56:32 -05:00
parent 6708c6cdfd
commit 09550f0f09
3 changed files with 16 additions and 4 deletions

View File

@@ -183,7 +183,9 @@ func main() {
s.ConfigureLogger()
// Start things up. Block here until done.
server.Run(s)
if err := server.Run(s); err != nil {
server.PrintAndDie(err.Error())
}
}
func configureTLS(opts *server.Options) {

View File

@@ -5,6 +5,7 @@ package server
// Run starts the NATS server. This wrapper function allows Windows to add a
// hook for running NATS as a service.
func Run(server *Server) {
func Run(server *Server) error {
server.Start()
return nil
}

View File

@@ -6,6 +6,7 @@ import (
"time"
"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/debug"
)
const serviceName = "gnatsd"
@@ -65,6 +66,14 @@ loop:
}
// Run starts the NATS server as a Windows service.
func Run(server *Server) {
svc.Run(serviceName, &winServiceWrapper{server})
func Run(server *Server) error {
run := svc.Run
isInteractive, err := svc.IsAnInteractiveSession()
if err != nil {
return err
}
if isInteractive {
run = debug.Run
}
return run(serviceName, &winServiceWrapper{server})
}