Skip to content

Commit

Permalink
Merge pull request #382 from nats-io/win-signals
Browse files Browse the repository at this point in the history
Differentiate signal handling for windows
  • Loading branch information
derekcollison authored Nov 22, 2016
2 parents ee70a09 + e9dc5fa commit e8dcb33
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 26 deletions.
26 changes: 0 additions & 26 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import (
"net"
"net/http"
"os"
"os/signal"
"runtime"
"strconv"
"sync"
"syscall"
"time"

// Allow dynamic profiling.
Expand Down Expand Up @@ -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()
Expand Down
34 changes: 34 additions & 0 deletions server/signal.go
Original file line number Diff line number Diff line change
@@ -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()
}
}
}()
}
26 changes: 26 additions & 0 deletions server/signal_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2012-2016 Apcera Inc. All rights reserved.

package server

import (
"os"
"os/signal"
)

// Signal Handling
func (s *Server) handleSignals() {
if s.opts.NoSigs {
return
}
c := make(chan os.Signal, 1)

signal.Notify(c, os.Interrupt)

go func() {
for sig := range c {
Debugf("Trapped %q signal", sig)
Noticef("Server Exiting..")
os.Exit(0)
}
}()
}

0 comments on commit e8dcb33

Please sign in to comment.