From ccca711edde4305ea69964d96f0d41f7669a7216 Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Tue, 22 Nov 2016 15:22:34 -0700 Subject: [PATCH 1/2] Differentiate signal handling for windows. Windows has limited support for signals, and does not define syscall.SIGUSR1. Log rotation will be handled differently in windows. * Add signal.go for all non-windows builds * Add signal_windows.go for windows builds. Today, windows looks to be the only platform that does not have syscall.SIGUSR1 defined. --- server/server.go | 26 -------------------------- server/signal.go | 34 ++++++++++++++++++++++++++++++++++ server/signal_windows.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 26 deletions(-) create mode 100644 server/signal.go create mode 100644 server/signal_windows.go diff --git a/server/server.go b/server/server.go index 5a161cf6164..50b9f5db6e6 100644 --- a/server/server.go +++ b/server/server.go @@ -11,11 +11,9 @@ import ( "net" "net/http" "os" - "os/signal" "runtime" "strconv" "sync" - "syscall" "time" // Allow dynamic profiling. @@ -182,30 +180,6 @@ func PrintServerAndExit() { os.Exit(0) } -// Signal Handling -func (s *Server) handleSignals() { - if s.opts.NoSigs { - return - } - c := make(chan os.Signal, 1) - - signal.Notify(c, syscall.SIGINT, syscall.SIGUSR1) - - go func() { - for sig := range c { - Debugf("Trapped %q signal", sig) - switch sig { - case syscall.SIGINT: - Noticef("Server Exiting..") - os.Exit(0) - case syscall.SIGUSR1: - // File log re-open for rotating file logs. - s.ReOpenLogFile() - } - } - }() -} - // Protected check on running state func (s *Server) isRunning() bool { s.mu.Lock() diff --git a/server/signal.go b/server/signal.go new file mode 100644 index 00000000000..909513d3e95 --- /dev/null +++ b/server/signal.go @@ -0,0 +1,34 @@ +// +build !windows +// Copyright 2012-2016 Apcera Inc. All rights reserved. + +package server + +import ( + "os" + "os/signal" + "syscall" +) + +// Signal Handling +func (s *Server) handleSignals() { + if s.opts.NoSigs { + return + } + c := make(chan os.Signal, 1) + + signal.Notify(c, syscall.SIGINT, syscall.SIGUSR1) + + go func() { + for sig := range c { + Debugf("Trapped %q signal", sig) + switch sig { + case syscall.SIGINT: + Noticef("Server Exiting..") + os.Exit(0) + case syscall.SIGUSR1: + // File log re-open for rotating file logs. + s.ReOpenLogFile() + } + } + }() +} diff --git a/server/signal_windows.go b/server/signal_windows.go new file mode 100644 index 00000000000..6118a8ba2b0 --- /dev/null +++ b/server/signal_windows.go @@ -0,0 +1,30 @@ +// Copyright 2012-2016 Apcera Inc. All rights reserved. + +package server + +import ( + "os" + "os/signal" + "syscall" +) + +// Signal Handling +func (s *Server) handleSignals() { + if s.opts.NoSigs { + return + } + c := make(chan os.Signal, 1) + + signal.Notify(c, syscall.SIGINT) + + go func() { + for sig := range c { + Debugf("Trapped %q signal", sig) + switch sig { + case syscall.SIGINT: + Noticef("Server Exiting..") + os.Exit(0) + } + } + }() +} From e9dc5fa0548b50802d7b8a77f47165bf026fe7b3 Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Tue, 22 Nov 2016 16:22:51 -0700 Subject: [PATCH 2/2] Updates based on comments --- server/signal_windows.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/server/signal_windows.go b/server/signal_windows.go index 6118a8ba2b0..c31a756038f 100644 --- a/server/signal_windows.go +++ b/server/signal_windows.go @@ -5,7 +5,6 @@ package server import ( "os" "os/signal" - "syscall" ) // Signal Handling @@ -15,16 +14,13 @@ func (s *Server) handleSignals() { } c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGINT) + signal.Notify(c, os.Interrupt) go func() { for sig := range c { Debugf("Trapped %q signal", sig) - switch sig { - case syscall.SIGINT: - Noticef("Server Exiting..") - os.Exit(0) - } + Noticef("Server Exiting..") + os.Exit(0) } }() }