Path: blob/main/cmd/grafana-agent-service/config_windows.go
4094 views
package main12import (3"fmt"4"path/filepath"56"golang.org/x/sys/windows/registry"7)89// config holds configuration options to run the service.10type config struct {11// ServicePath points to the path of the managed Grafana Agent binary.12ServicePath string1314// Args holds arguments to pass to the Grafana Agent binary. os.Args[0] is15// not included.16Args []string1718// WorkingDirectory points to the working directory to run the Grafana Agent19// binary from.20WorkingDirectory string21}2223// loadConfig loads the config from the Windows registry.24func loadConfig() (*config, error) {25// NOTE(rfratto): the key name below shouldn't be changed without being26// able to either migrate from the old key to the new key or supporting27// both the old and the new key at the same time.2829agentKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `Software\Grafana\Grafana Agent Flow`, registry.READ)30if err != nil {31return nil, fmt.Errorf("failed to open registry: %w", err)32}3334servicePath, _, err := agentKey.GetStringValue("")35if err != nil {36return nil, fmt.Errorf("failed to retrieve key (Default): %w", err)37}3839args, _, err := agentKey.GetStringsValue("Arguments")40if err != nil {41return nil, fmt.Errorf("failed to retrieve key Arguments: %w", err)42}4344return &config{45ServicePath: servicePath,46Args: args,47WorkingDirectory: filepath.Dir(servicePath),48}, nil49}505152