This can cause problems because the service manager has a very short timeout between when it starts a process and expects that process to communicate that it is in StartPending state. For Windows we need to move this as close as possible to the start of the run function.
Currently
elastic-agent
does several things before it communicates with the Windows Service Manager and registers itself and reports as running.https://github.com/elastic/elastic-agent/blob/81e112dfb6202d24a0b2a8d73067b091c3647cf0/internal/pkg/agent/cmd/run.go#L143
This can cause problems because the service manager has a very short timeout between when it starts a process and expects that process to communicate that it is in StartPending state. For Windows we need to move this as close as possible to the start of the run function.