Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to run Collector as Windows Service #1119

Closed
james-bebbington opened this issue Jun 15, 2020 · 1 comment
Closed

Add ability to run Collector as Windows Service #1119

james-bebbington opened this issue Jun 15, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@james-bebbington
Copy link
Member

james-bebbington commented Jun 15, 2020

When running the Collector on Windows, users will generally want to run this as a Windows service. It's not possible to just run a .exe directly as a Windows service, so some minor modifications need to be made to the startup/service code.

Suggested implementation:

Add a separate main method on Windows (using build flags):

  • Check if the executable is running interactively & if so, run the Collector as normal
  • Otherwise, if the executable has been invoked from service control manager, implement the Handler interface as a wrapper around service.Application, and call svc.Run on this handler
    • In order to make minimal changes to existing code, make the signalsChannel, that is used to be notified of OS SIGTERM signals, available for this wrapper to use when the Windows svc.Stop or svc.Shutdown signals are received (see example code below).
    • Allow a zap hook to be supplied to service.newLogger() so that logging can be redirected to the Windows Event Viewer instead of being lost. We may want to limit this to INFO+ (or WARNING+) logs.

Sample code:

type WindowsService struct {}

func (m *WindowsService) Execute(args []string, requests <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
	...

	go func() {
		err = app.Start()
		if err != nil {
			log.Fatalf("application run finished with error: %v", err)
		}
	}()

	changes <- svc.Status{State: svc.Running, Accepts: svc.AcceptStop | svc.AcceptShutdown}

	for req := range requests {
		switch req.Cmd {
		case svc.Interrogate:
			changes <- req.CurrentStatus
		case svc.Stop, svc.Shutdown:
			app.signalsChannel <- syscall.SIGTERM
			changes <- svc.Status{State: svc.StopPending}
			return
		default:
			log.Fatalf(fmt.Sprintf("unexpected control request #%d", req))
		}
	}
}
@james-bebbington
Copy link
Member Author

(can assign this to me)

@flands flands added this to the GA 1.0 milestone Jun 18, 2020
@flands flands closed this as completed Jul 7, 2020
@flands flands modified the milestones: GA 1.0, Beta 0.6.0 Jul 16, 2020
@andrewhsu andrewhsu added the enhancement New feature or request label Jan 6, 2021
MovieStoreGuy pushed a commit to atlassian-forks/opentelemetry-collector that referenced this issue Nov 11, 2021
hughesjj pushed a commit to hughesjj/opentelemetry-collector that referenced this issue Apr 27, 2023
…y#1119)

Bumps [boto3](https://github.com/boto/boto3) from 1.20.33 to 1.20.34.
- [Release notes](https://github.com/boto/boto3/releases)
- [Changelog](https://github.com/boto/boto3/blob/develop/CHANGELOG.rst)
- [Commits](boto/boto3@1.20.33...1.20.34)

---
updated-dependencies:
- dependency-name: boto3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Troels51 pushed a commit to Troels51/opentelemetry-collector that referenced this issue Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants