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

optimize windows service startup #1806

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions cmd/launcher/svc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const serviceName = "launcher"

// runWindowsSvc starts launcher as a windows service. This will
// probably not behave correctly if you start it from the command line.
// This method is responsible for calling svc.Run, which eventually translates into the
// Execute function below. Each device has a global ServicesPipeTimeout value (typically at
// 30-45 seconds but depends on the configuration of the device). We have that many seconds
// to get from here to the point in Execute where we return a service status of Running before
// service control manager will consider the start attempt to have timed out, cancel it,
// and proceed without attempting restart.
// Wherever possible, we should keep any connections or timely operations out of this method,
// and ensure they are added late enough in Execute to avoid hitting this timeout.
func runWindowsSvc(systemSlogger *multislogger.MultiSlogger, args []string) error {
systemSlogger.Log(context.TODO(), slog.LevelInfo,
"service start requested",
Expand Down Expand Up @@ -65,9 +73,6 @@ func runWindowsSvc(systemSlogger *multislogger.MultiSlogger, args []string) erro
systemSlogger.AddHandler(localSloggerHandler)
}

// Confirm that service configuration is up-to-date
checkServiceConfiguration(localSlogger.Logger, opts)

systemSlogger.Log(context.TODO(), slog.LevelInfo,
"launching service",
"version", version.Version().Version,
Expand Down Expand Up @@ -165,8 +170,13 @@ func (w *winSvc) Execute(args []string, r <-chan svc.ChangeRequest, changes chan
w.systemSlogger.Log(ctx, slog.LevelInfo,
"windows service starting",
)
// after this point windows service control manager will know that we've successfully started,
// it is safe to begin longer running operations
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}

// Confirm that service configuration is up-to-date
go checkServiceConfiguration(w.slogger.Logger, w.opts)

ctx = ctxlog.NewContext(ctx, w.logger)
runLauncherResults := make(chan struct{})

Expand Down
Loading