From 722c2e73595dbba01dc113703b6173ff0fd67c6b Mon Sep 17 00:00:00 2001 From: Ago Allikmaa Date: Tue, 8 Dec 2020 14:27:33 +0200 Subject: [PATCH 1/3] Env var NO_WINDOWS_SERVICE to force interactive mode on Windows --- cmd/otelcol/main_windows.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/otelcol/main_windows.go b/cmd/otelcol/main_windows.go index e30e866e95a..b4e03cbadba 100644 --- a/cmd/otelcol/main_windows.go +++ b/cmd/otelcol/main_windows.go @@ -18,6 +18,7 @@ package main import ( "fmt" + "os" "golang.org/x/sys/windows/svc" @@ -25,18 +26,27 @@ import ( ) 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 { From 94a146aa8bc0e66a960a399bdfce03364191190f Mon Sep 17 00:00:00 2001 From: Ago Allikmaa Date: Tue, 8 Dec 2020 14:54:02 +0200 Subject: [PATCH 2/3] Some renaming for better clarity. --- cmd/otelcol/main_windows.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/otelcol/main_windows.go b/cmd/otelcol/main_windows.go index b4e03cbadba..0a265b11ab9 100644 --- a/cmd/otelcol/main_windows.go +++ b/cmd/otelcol/main_windows.go @@ -26,16 +26,16 @@ import ( ) func run(params service.Parameters) error { - if isInteractiveMode, err := checkInteractiveMode(); err != nil { + if useInteractiveMode, err := checkUseInteractiveMode(); err != nil { return err - } else if isInteractiveMode { + } else if useInteractiveMode { return runInteractive(params) } else { return runService(params) } } -func checkInteractiveMode() (bool, error) { +func checkUseInteractiveMode() (bool, error) { if value, present := os.LookupEnv("NO_WINDOWS_SERVICE"); present && value != "0" { return true, nil } From ac5334179c9eb74a69f8439e8ca51029c96edeb3 Mon Sep 17 00:00:00 2001 From: Ago Allikmaa Date: Tue, 15 Dec 2020 03:40:12 +0200 Subject: [PATCH 3/3] Comments/docs for NO_WINDOWS_SERVICE env var --- cmd/otelcol/main_windows.go | 4 ++++ docs/troubleshooting.md | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/cmd/otelcol/main_windows.go b/cmd/otelcol/main_windows.go index 0a265b11ab9..c066c39616b 100644 --- a/cmd/otelcol/main_windows.go +++ b/cmd/otelcol/main_windows.go @@ -36,6 +36,10 @@ func run(params service.Parameters) error { } func checkUseInteractiveMode() (bool, error) { + // If environment variable NO_WINDOWS_SERVICE is set with any value other + // than 0, use interactive mode instead of running as a service. This should + // be set in case running as a service is not possible or desired even + // though the current session is not detected to be interactive if value, present := os.LookupEnv("NO_WINDOWS_SERVICE"); present && value != "0" { return true, nil } diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 465695a8682..5e1d6e2eeb2 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -258,3 +258,11 @@ More often than not, exporting data does not work because of a network configuration issue. This could be due to a firewall, DNS, or proxy issue. Note that the Collector does have [proxy support](https://github.com/open-telemetry/opentelemetry-collector/tree/master/exporter#proxy-support). + +### Startup failing in Windows Docker containers + +The process may fail to start in a Windows Docker container with the following +error: `The service process could not connect to the service controller`. In +this case the `NO_WINDOWS_SERVICE=1` environment variable should be set to force +the collector to be started as if it were running in an interactive terminal, +without attempting to run as a Windows service. \ No newline at end of file