Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shutdown on Ctrl+C #1186

Merged
merged 1 commit into from Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,5 +1,6 @@
language: go
go:
- 1.13.x
- 1.12.x
addons:
apt:
Expand Down
2 changes: 2 additions & 0 deletions main.go
Expand Up @@ -17,6 +17,7 @@ import (
"flag"
"fmt"
"os"
"runtime"

"github.com/nats-io/nats-server/v2/server"
)
Expand Down Expand Up @@ -109,4 +110,5 @@ func main() {
if err := server.Run(s); err != nil {
server.PrintAndDie(err.Error())
}
runtime.Goexit()
}
3 changes: 2 additions & 1 deletion server/server.go
Expand Up @@ -1168,7 +1168,7 @@ func (s *Server) Shutdown() {
s.mu.Unlock()
return
}
s.Noticef("Server Exiting..")
s.Noticef("Initiating Shutdown...")

opts := s.getOpts()

Expand Down Expand Up @@ -1271,6 +1271,7 @@ func (s *Server) Shutdown() {
s.deletePortsFile(opts.PortsFileDir)
}

s.Noticef("Server Exiting..")
// Close logger if applicable. It allows tests on Windows
// to be able to do proper cleanup (delete log file).
s.logging.RLock()
Expand Down
7 changes: 3 additions & 4 deletions server/service_windows.go
Expand Up @@ -18,7 +18,6 @@ import (
"time"

"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/debug"
)

const (
Expand Down Expand Up @@ -110,15 +109,15 @@ func Run(server *Server) error {
server.Start()
return nil
}
run := svc.Run
isInteractive, err := svc.IsAnInteractiveSession()
if err != nil {
return err
}
if isInteractive {
run = debug.Run
server.Start()
return nil
}
return run(serviceName, &winServiceWrapper{server})
return svc.Run(serviceName, &winServiceWrapper{server})
}

// isWindowsService indicates if NATS is running as a Windows service.
Expand Down
2 changes: 1 addition & 1 deletion server/signal.go
Expand Up @@ -49,7 +49,7 @@ func (s *Server) handleSignals() {
s.Debugf("Trapped %q signal", sig)
switch sig {
case syscall.SIGINT:
s.Noticef("Server Exiting..")
s.Shutdown()
derekcollison marked this conversation as resolved.
Show resolved Hide resolved
os.Exit(0)
case syscall.SIGUSR1:
// File log re-open for rotating file logs.
Expand Down
2 changes: 1 addition & 1 deletion server/signal_windows.go
Expand Up @@ -35,7 +35,7 @@ func (s *Server) handleSignals() {
go func() {
for sig := range c {
s.Debugf("Trapped %q signal", sig)
s.Noticef("Server Exiting..")
s.Shutdown()
os.Exit(0)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion test/configs/authorization.conf
Expand Up @@ -5,7 +5,7 @@ authorization {
include "auths.conf"

# Just foo for testing
PASS: $2a$10$UHR6GhotWhpLsKtVP0/i6.Nh9.fuY73cWjLoJjb2sKT8KISBcUW5q
PASS: $2a$04$P/.bd.7unw9Ew7yWJqXsl.f4oNRLQGvadEL2YnqQXbbb.IVQajRdK

# Users listed with permissions.
users = [
Expand Down
56 changes: 0 additions & 56 deletions vendor/golang.org/x/sys/windows/svc/debug/log.go

This file was deleted.

45 changes: 0 additions & 45 deletions vendor/golang.org/x/sys/windows/svc/debug/service.go

This file was deleted.

1 change: 0 additions & 1 deletion vendor/modules.txt
Expand Up @@ -16,7 +16,6 @@ golang.org/x/crypto/ed25519/internal/edwards25519
# golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e
golang.org/x/sys/windows/svc/eventlog
golang.org/x/sys/windows/svc
golang.org/x/sys/windows/svc/debug
golang.org/x/sys/windows/svc/mgr
golang.org/x/sys/windows
golang.org/x/sys/windows/registry