Merge pull request #1276 from DiniFarb/win_srv_stop_error

fix: Windows service can't stop without an error
This commit is contained in:
Ben Reedy 2023-08-26 08:34:04 +10:00 committed by GitHub
commit f7426e9fad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,14 +32,14 @@ loop:
changes <- c.CurrentStatus
case svc.Stop, svc.Shutdown:
_ = logger.Info(100, "Service Stop Received")
s.stopCh <- true
changes <- svc.Status{State: svc.StopPending}
break loop
default:
_ = logger.Error(102, fmt.Sprintf("unexpected control request #%d", c))
}
}
}
changes <- svc.Status{State: svc.StopPending}
s.stopCh <- true
return
}
@ -48,7 +48,7 @@ var StopCh = make(chan bool)
func init() {
isService, err := svc.IsWindowsService()
if err != nil {
logger, err := eventlog.Open("windows_exporter")
logger, err = eventlog.Open("windows_exporter")
if err != nil {
os.Exit(2)
}
@ -57,7 +57,7 @@ func init() {
}
if isService {
logger, err := eventlog.Open("windows_exporter")
logger, err = eventlog.Open("windows_exporter")
if err != nil {
os.Exit(2)
}