func()

in cmd/ops_agent_windows/run_windows.go [58:104]


func (s *service) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
	changes <- svc.Status{State: svc.StartPending}

	allArgs := append([]string{}, os.Args[1:]...)
	allArgs = append(allArgs, args[1:]...)
	if err := s.parseFlags(allArgs); err != nil {
		s.log.Error(EngineEventID, fmt.Sprintf("failed to parse arguments: %v", err))
		// ERROR_INVALID_ARGUMENT
		return false, 0x00000057
	}

	if err := s.generateConfigs(ctx); err != nil {
		s.log.Error(EngineEventID, fmt.Sprintf("failed to generate config files: %v", err))
		// 2 is "file not found"
		return false, 2
	}
	s.log.Info(EngineEventID, "generated configuration files")
	s.runHealthChecks()

	changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
	if err := s.startSubagents(); err != nil {
		s.log.Error(EngineEventID, fmt.Sprintf("failed to start subagents: %v", err))
		// TODO: Ignore failures for partial startup?
	}
	s.log.Info(EngineEventID, "started subagents")
	defer func() {
		changes <- svc.Status{State: svc.StopPending}
	}()
	for {
		select {
		case c := <-r:
			switch c.Cmd {
			case svc.Interrogate:
				changes <- c.CurrentStatus
			case svc.Stop, svc.Shutdown:
				return
			default:
				s.log.Error(EngineEventID, fmt.Sprintf("unexpected control request #%d", c))
			}
		case <-ctx.Done():
			return
		}
	}
}