Skip to content

Commit

Permalink
use IsWindowsService to detect if running as service
Browse files Browse the repository at this point in the history
Signed-off-by: James Sturtevant <jstur@microsoft.com>
  • Loading branch information
jsturtevant committed Nov 5, 2021
1 parent 947d847 commit a6ea021
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions exporter.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package main
Expand Down Expand Up @@ -324,13 +325,13 @@ func main() {

initWbem()

isInteractive, err := svc.IsAnInteractiveSession()
isService, err := svc.IsWindowsService()
if err != nil {
log.Fatal(err)
}

stopCh := make(chan bool)
if !isInteractive {
if isService {
go func() {
err = svc.Run(serviceName, &windowsExporterService{stopCh: stopCh})
if err != nil {
Expand Down

0 comments on commit a6ea021

Please sign in to comment.