Skip to content

Commit

Permalink
Env var NO_WINDOWS_SERVICE to force interactive mode on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
agoallikmaa committed Dec 8, 2020
1 parent 65588cc commit 722c2e7
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions cmd/otelcol/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,35 @@ package main

import (
"fmt"
"os"

"golang.org/x/sys/windows/svc"

"go.opentelemetry.io/collector/service"
)

func run(params service.Parameters) error {
isInteractive, err := svc.IsAnInteractiveSession()
if err != nil {
return fmt.Errorf("failed to determine if we are running in an interactive session %w", err)
}

if isInteractive {
if isInteractiveMode, err := checkInteractiveMode(); err != nil {
return err
} else if isInteractiveMode {
return runInteractive(params)
} else {
return runService(params)
}
}

func checkInteractiveMode() (bool, error) {
if value, present := os.LookupEnv("NO_WINDOWS_SERVICE"); present && value != "0" {
return true, nil
}

if isInteractiveSession, err := svc.IsAnInteractiveSession(); err != nil {
return false, fmt.Errorf("failed to determine if we are running in an interactive session %w", err)
} else {
return isInteractiveSession, nil
}
}

func runService(params service.Parameters) error {
// do not need to supply service name when startup is invoked through Service Control Manager directly
if err := svc.Run("", service.NewWindowsService(params)); err != nil {
Expand Down

0 comments on commit 722c2e7

Please sign in to comment.