From 2153a450505e0595788cff152ef81aee7c64e134 Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Thu, 16 Aug 2018 10:21:01 -0600 Subject: [PATCH] Update service and syslog code to use variable instead of constant for the process name and service name. This allows the reuse of this code in NATS Streaming Server by invoking the new setters to change the service and process names. Signed-off-by: Ivan Kozlovic --- logger/syslog.go | 4 ++++ logger/syslog_windows.go | 9 ++++++--- server/const.go | 2 +- server/service_windows.go | 8 +++++++- server/signal.go | 11 ++++++++--- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/logger/syslog.go b/logger/syslog.go index 96d65ca676b..7d7713b3df6 100644 --- a/logger/syslog.go +++ b/logger/syslog.go @@ -31,6 +31,10 @@ type SysLogger struct { trace bool } +// SetSyslogName sets the name to use for the syslog. +// Currently used only on Windows. +func SetSyslogName(name string) {} + // GetSysLoggerTag generates the tag name for use in syslog statements. If // the executable is linked, the name of the link will be used as the tag, // otherwise, the name of the executable is used. "gnatsd" is the default diff --git a/logger/syslog_windows.go b/logger/syslog_windows.go index 7e780812e7a..54972062e30 100644 --- a/logger/syslog_windows.go +++ b/logger/syslog_windows.go @@ -22,9 +22,12 @@ import ( "golang.org/x/sys/windows/svc/eventlog" ) -const ( - natsEventSource = "NATS-Server" -) +var natsEventSource = "NATS-Server" + +// SetSyslogName sets the name to use for the system log event source +func SetSyslogName(name string) { + natsEventSource = name +} // SysLogger logs to the windows event logger type SysLogger struct { diff --git a/server/const.go b/server/const.go index b27ae5d9d64..5a8362acc1c 100644 --- a/server/const.go +++ b/server/const.go @@ -35,7 +35,7 @@ var ( const ( // VERSION is the current version for the server. - VERSION = "1.2.0" + VERSION = "1.3.0" // PROTO is the currently supported protocol. // 0 was the original diff --git a/server/service_windows.go b/server/service_windows.go index 43cc2b5ceec..0b9fa949684 100644 --- a/server/service_windows.go +++ b/server/service_windows.go @@ -22,12 +22,18 @@ import ( ) const ( - serviceName = "gnatsd" reopenLogCode = 128 reopenLogCmd = svc.Cmd(reopenLogCode) acceptReopenLog = svc.Accepted(reopenLogCode) ) +var serviceName = "gnatsd" + +// SetServiceName allows setting a different service name +func SetServiceName(name string) { + serviceName = name +} + // winServiceWrapper implements the svc.Handler interface for implementing // gnatsd as a Windows service. type winServiceWrapper struct { diff --git a/server/signal.go b/server/signal.go index 6a432f7c508..8402214905c 100644 --- a/server/signal.go +++ b/server/signal.go @@ -26,7 +26,12 @@ import ( "syscall" ) -const processName = "gnatsd" +var processName = "gnatsd" + +// SetProcessName allows to change the expected name of the process. +func SetProcessName(name string) { + processName = name +} // Signal Handling func (s *Server) handleSignals() { @@ -76,10 +81,10 @@ func ProcessSignal(command Command, pidStr string) error { return err } if len(pids) == 0 { - return errors.New("no gnatsd processes running") + return fmt.Errorf("no %s processes running", processName) } if len(pids) > 1 { - errStr := "multiple gnatsd processes running:\n" + errStr := fmt.Sprintf("multiple %s processes running:\n", processName) prefix := "" for _, p := range pids { errStr += fmt.Sprintf("%s%d", prefix, p)