mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-21 20:26:36 +00:00
fix: log to the Windows temp directory if of service detection failures. (#1890)
This commit is contained in:
@@ -56,8 +56,7 @@ var IsService = func() bool {
|
|||||||
|
|
||||||
isService, err := svc.IsWindowsService()
|
isService, err := svc.IsWindowsService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//nolint:gosec
|
logToFile(fmt.Sprintf("failed to detect service: %v", err))
|
||||||
_ = os.WriteFile("C:\\Program Files\\windows_exporter\\start-service.error.log", []byte(fmt.Sprintf("failed to detect service: %v", err)), 0o644)
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -70,7 +69,9 @@ var IsService = func() bool {
|
|||||||
go func() {
|
go func() {
|
||||||
err := svc.Run(serviceName, &windowsExporterService{})
|
err := svc.Run(serviceName, &windowsExporterService{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = logToEventToLog(windows.EVENTLOG_ERROR_TYPE, fmt.Sprintf("failed to start service: %v", err))
|
if logErr := logToEventToLog(windows.EVENTLOG_ERROR_TYPE, fmt.Sprintf("failed to start service: %v", err)); logErr != nil {
|
||||||
|
logToFile(fmt.Sprintf("failed to start service: %v", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceManagerFinishedCh <- struct{}{}
|
serviceManagerFinishedCh <- struct{}{}
|
||||||
@@ -78,8 +79,7 @@ var IsService = func() bool {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
if err := logToEventToLog(windows.EVENTLOG_INFORMATION_TYPE, "attempting to start exporter service"); err != nil {
|
if err := logToEventToLog(windows.EVENTLOG_INFORMATION_TYPE, "attempting to start exporter service"); err != nil {
|
||||||
//nolint:gosec
|
logToFile(fmt.Sprintf("failed sent log to event log: %v", err))
|
||||||
_ = os.WriteFile("C:\\Program Files\\windows_exporter\\start-service.error.log", []byte(fmt.Sprintf("failed sent log to event log: %v", err)), 0o644)
|
|
||||||
|
|
||||||
exitCodeCh <- 2
|
exitCodeCh <- 2
|
||||||
}
|
}
|
||||||
@@ -149,3 +149,10 @@ func logToEventToLog(eType uint16, msg string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func logToFile(msg string) {
|
||||||
|
if file, err := os.CreateTemp("", "windows_exporter.service.error.log"); err == nil {
|
||||||
|
_, _ = file.WriteString(msg)
|
||||||
|
_ = file.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user