func main()

in cmd/google_guest_agent/google_guest_agent.go [104:157]


func main() {
	extraCfg, err := readExtraConfig()
	if err != nil {
		fmt.Fprintln(os.Stderr, "Failed to read extra config:", err)
		os.Exit(1)
	}
	if err := cfg.Load(extraCfg); err != nil {
		fmt.Fprintln(os.Stderr, "Failed to load config:", err)
		os.Exit(1)
	}

	setupFlags()
	ctx, cancel := context.WithCancel(context.Background())

	logOpts.ProgramVersion = version
	logOpts.ACSClientDebugLogging = cfg.Retrieve().ACS.ClientDebugLogging
	if err := logger.Init(ctx, logOpts); err != nil {
		fmt.Fprintln(os.Stderr, "Failed to initialize logger:", err)
		os.Exit(1)
	}

	if err := service.Init(ctx, func() {
		galog.Info("Google Guest Agent Leaving (canceling context)...")
		galog.Shutdown(galogShutdownTimeout)
		cancel()
	}, daemon.GuestAgentManager); err != nil {
		galog.Fatalf("Failed to initialize service manager: %s", err)
	}

	// MDS watcher is disabled in test environment as its not accessible. It must
	// not be set otherwise.
	if os.Getenv("TEST_UNDECLARED_OUTPUTS_DIR") != "" {
		galog.Infof("MDS watcher is disabled in config, skipping MDS watcher initialization")
	} else {
		if err := events.FetchManager().AddWatcher(ctx, metadata.NewWatcher()); err != nil {
			galog.Fatalf("Failed to add metadata watcher: %v", err)
		}
	}

	opts := setup.Config{Version: version, CorePluginPath: corePluginPath, SkipCorePlugin: ignoreCorePlugin()}
	// ACS watcher requires ACS client enabled.
	if (forceOnDemandPlugins || cfg.Retrieve().Core.OnDemandPlugins) && cfg.Retrieve().Core.ACSClient {
		opts.EnableACSWatcher = true
	}

	galog.Infof("Initializing Google Guest Agent...")
	if err := setup.Run(ctx, opts); err != nil {
		galog.Fatalf("Failed to initialize Guest Agent with required Core Plugin: %v", err)
	}

	if err := events.FetchManager().Run(ctx); err != nil {
		galog.Fatalf("Failed to run events manager: %v", err)
	}
}