Documentation
¶
Overview ¶
Package agent contains the public interfaces, functions, consts, and vars for the viam-server agent.
Index ¶
- Constants
- Variables
- func CheckIfSame(path1, path2 string) (bool, error)
- func ConvertAttributes[T any](attributes *structpb.Struct) (*T, error)
- func DecompressFile(inPath string) (outPath string, errRet error)
- func DownloadFile(ctx context.Context, rawURL string) (outPath string, errRet error)
- func ForceSymlink(orig, symlink string) error
- func GetFileSum(filepath string) (outSum []byte, errRet error)
- func GetRevision() string
- func GetVersion() string
- func InitPaths() error
- func SyncFS(syncPath string) (errRet error)
- func WriteFileIfNew(outPath string, data []byte) (bool, error)
- type AgentSubsystem
- func (s *AgentSubsystem) HealthCheck(ctx context.Context) error
- func (s *AgentSubsystem) LoadCache() error
- func (s *AgentSubsystem) SaveCache() error
- func (s *AgentSubsystem) Start(ctx context.Context) error
- func (s *AgentSubsystem) Stop(ctx context.Context) error
- func (s *AgentSubsystem) Update(ctx context.Context, cfg *pb.DeviceSubsystemConfig) (bool, error)
- func (s *AgentSubsystem) Version() string
- type BasicSubsystem
- type CacheData
- type InternalSubsystem
- func (is *InternalSubsystem) HealthCheck(ctx context.Context) (errRet error)
- func (is *InternalSubsystem) Start(ctx context.Context) error
- func (is *InternalSubsystem) Stop(ctx context.Context) error
- func (is *InternalSubsystem) Update(ctx context.Context, cfg *pb.DeviceSubsystemConfig, newVersion bool) (bool, error)
- type Manager
- func (m *Manager) CheckUpdates(ctx context.Context) time.Duration
- func (m *Manager) CloseAll()
- func (m *Manager) CreateNetAppender() (*logging.NetAppender, error)
- func (m *Manager) GetConfig(ctx context.Context) (map[string]*pb.DeviceSubsystemConfig, time.Duration, error)
- func (m *Manager) LoadConfig(cfgPath string) error
- func (m *Manager) LoadSubsystems(ctx context.Context) error
- func (m *Manager) SelfUpdate(ctx context.Context) (bool, error)
- func (m *Manager) StartBackgroundChecks(ctx context.Context)
- func (m *Manager) StartSubsystem(ctx context.Context, name string) error
- func (m *Manager) SubsystemHealthChecks(ctx context.Context)
- func (m *Manager) SubsystemUpdates(ctx context.Context, cfg map[string]*pb.DeviceSubsystemConfig)
- type MatchingLogger
- type VersionInfo
Constants ¶
const ( ShortFailTime = time.Second * 30 StartTimeout = time.Minute StopTermTimeout = time.Second * 30 StopKillTimeout = time.Second * 10 )
const (
SubsystemName = "viam-agent"
)
Variables ¶
var ( // versions embedded at build time. Version = "" GitRevision = "" ViamDirs = map[string]string{"viam": "/opt/viam"} )
var ErrSubsystemDisabled = errors.New("subsystem disabled")
Functions ¶
func CheckIfSame ¶
func ConvertAttributes ¶ added in v0.9.0
func DecompressFile ¶
DecompressFile extracts a compressed file and returns the path to the extracted file.
func DownloadFile ¶
DownloadFile downloads a file into the cache directory and returns a path to the file.
func ForceSymlink ¶
func GetFileSum ¶
func GetRevision ¶ added in v0.9.0
func GetRevision() string
GetRevision returns the git revision embedded at build time.
func GetVersion ¶ added in v0.9.0
func GetVersion() string
GetVersion returns the version embedded at build time.
Types ¶
type AgentSubsystem ¶
type AgentSubsystem struct { CacheData *CacheData // contains filtered or unexported fields }
AgentSubsystem is a wrapper for the real subsystems, mostly allowing sharing of download/update code.
func NewAgentSubsystem ¶
func NewAgentSubsystem( ctx context.Context, name string, logger logging.Logger, subsys BasicSubsystem, ) (*AgentSubsystem, error)
NewAgentSubsystem returns a new wrapped subsystem.
func (*AgentSubsystem) HealthCheck ¶
func (s *AgentSubsystem) HealthCheck(ctx context.Context) error
HealthCheck calls the inner subsystem's HealthCheck() to verify, and logs failures/successes.
func (*AgentSubsystem) LoadCache ¶
func (s *AgentSubsystem) LoadCache() error
LoadCache loads the cached data for the subsystem from disk.
func (*AgentSubsystem) SaveCache ¶
func (s *AgentSubsystem) SaveCache() error
SaveCache saves the cached data to disk.
func (*AgentSubsystem) Start ¶
func (s *AgentSubsystem) Start(ctx context.Context) error
Start starts the subsystem.
func (*AgentSubsystem) Stop ¶
func (s *AgentSubsystem) Stop(ctx context.Context) error
Stop stops the subsystem.
func (*AgentSubsystem) Update ¶
func (s *AgentSubsystem) Update(ctx context.Context, cfg *pb.DeviceSubsystemConfig) (bool, error)
Update is the main function of the AgentSubsystem wrapper, as it's shared between subsystems. Returns true if a restart is needed.
func (*AgentSubsystem) Version ¶
func (s *AgentSubsystem) Version() string
Version returns the running version.
type BasicSubsystem ¶
type BasicSubsystem interface { // Start runs the subsystem Start(ctx context.Context) error // Stop signals the subsystem to shutdown Stop(ctx context.Context) error // HealthCheck reports if a subsystem is running correctly (it is restarted if not) HealthCheck(ctx context.Context) error }
BasicSubsystem is the minimal interface.
type CacheData ¶
type CacheData struct { CurrentVersion string `json:"current_version"` PreviousVersion string `json:"previous_version"` Versions map[string]*VersionInfo `json:"versions"` }
CacheData stores VersionInfo and the current/previous versions for (TODO) rollback.
type InternalSubsystem ¶ added in v0.2.0
type InternalSubsystem struct {
// contains filtered or unexported fields
}
InternalSubsystem is shared start/stop/update code between "internal" (not viam-server) subsystems.
func NewInternalSubsystem ¶ added in v0.2.0
func (*InternalSubsystem) HealthCheck ¶ added in v0.2.0
func (is *InternalSubsystem) HealthCheck(ctx context.Context) (errRet error)
HealthCheck sends a USR1 signal to the subsystem process, which should cause it to log "HEALTHY" to stdout.
func (*InternalSubsystem) Start ¶ added in v0.2.0
func (is *InternalSubsystem) Start(ctx context.Context) error
func (*InternalSubsystem) Stop ¶ added in v0.2.0
func (is *InternalSubsystem) Stop(ctx context.Context) error
func (*InternalSubsystem) Update ¶ added in v0.2.0
func (is *InternalSubsystem) Update(ctx context.Context, cfg *pb.DeviceSubsystemConfig, newVersion bool) (bool, error)
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the core of the agent process, and maintains the list of subsystems, as well as cloud connection.
func NewManager ¶
NewManager returns a new Manager.
func (*Manager) CheckUpdates ¶
CheckUpdates retrieves an updated config from the cloud, and then passes it to SubsystemUpdates().
func (*Manager) CloseAll ¶
func (m *Manager) CloseAll()
CloseAll stops all subsystems and closes the cloud connection.
func (*Manager) CreateNetAppender ¶ added in v0.4.0
func (m *Manager) CreateNetAppender() (*logging.NetAppender, error)
CreateNetAppender creates or replaces m.netAppender. Must be called after config is loaded.
func (*Manager) GetConfig ¶
func (m *Manager) GetConfig(ctx context.Context) (map[string]*pb.DeviceSubsystemConfig, time.Duration, error)
GetConfig retrieves the configuration from the cloud, or returns a cached version if unable to communicate.
func (*Manager) LoadConfig ¶ added in v0.1.0
func (*Manager) LoadSubsystems ¶
LoadSubsystems runs at startup, before getting online.
func (*Manager) SelfUpdate ¶
SelfUpdate is called early in startup to update the viam-agent subsystem before any other work is started.
func (*Manager) StartBackgroundChecks ¶
StartBackgroundChecks kicks off a go routine that loops on a timer to check for updates and health checks.
func (*Manager) StartSubsystem ¶ added in v0.1.0
StartSubsystem may be called early in startup when no cloud connectivity is configured.
func (*Manager) SubsystemHealthChecks ¶
SubsystemHealthChecks makes sure all subsystems are responding, and restarts them if not.
func (*Manager) SubsystemUpdates ¶
SubsystemUpdates checks for updates to configured subsystems and restarts them as needed.
type MatchingLogger ¶ added in v0.1.0
type MatchingLogger struct {
// contains filtered or unexported fields
}
MatchingLogger provides a logger that also allows sending regex matched lines to a channel.
func NewMatchingLogger ¶ added in v0.1.0
func NewMatchingLogger(logger logging.Logger, isError, uploadAll bool) *MatchingLogger
NewMatchingLogger returns a MatchingLogger.
func (*MatchingLogger) AddMatcher ¶ added in v0.1.0
func (l *MatchingLogger) AddMatcher(name string, regex *regexp.Regexp, mask bool) (<-chan []string, error)
AddMatcher adds a named regex to filter from results and return to a channel, optionally masking it from normal logging.
func (*MatchingLogger) DeleteMatcher ¶ added in v0.1.0
func (l *MatchingLogger) DeleteMatcher(name string)
DeleteMatcher removes a previously added matcher.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
Package subsystems defines the subsystem interface.
|
Package subsystems defines the subsystem interface. |
provisioning
Package provisioning is the subsystem responsible for network/wifi management, and initial device setup via hotspot.
|
Package provisioning is the subsystem responsible for network/wifi management, and initial device setup via hotspot. |
registry
Package registry is used to register subsystems from other packages.
|
Package registry is used to register subsystems from other packages. |
syscfg
Package syscfg contains the system configuration agent subsystem.
|
Package syscfg contains the system configuration agent subsystem. |
viamagent
Package viamagent is the subsystem for the viam-agent itself.
|
Package viamagent is the subsystem for the viam-agent itself. |
viamserver
Package viamserver contains the viam-server agent subsystem.
|
Package viamserver contains the viam-server agent subsystem. |