-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #382 from nats-io/win-signals
Differentiate signal handling for windows
- Loading branch information
Showing
3 changed files
with
60 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}() | ||
} |