updater

package
v0.0.59 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackupInfo added in v0.0.21

type BackupInfo struct {
	Component   string    `json:"component"`
	BackupPath  string    `json:"backup_path"`
	OriginalDir string    `json:"original_dir"`
	Version     string    `json:"version"`
	CreatedAt   time.Time `json:"created_at"`
}

BackupInfo stores information about a backup for rollback

type Component

type Component struct {
	Name           string    `json:"name"`
	CurrentVersion string    `json:"current_version"`
	LatestVersion  string    `json:"latest_version,omitempty"`
	UpdateAvail    bool      `json:"update_available"`
	Repository     string    `json:"repository"`
	AssetPattern   string    `json:"asset_pattern"` // e.g., "spatialnvr-linux-{arch}"
	InstallPath    string    `json:"install_path"`
	LastChecked    time.Time `json:"last_checked"`
	AutoUpdate     bool      `json:"auto_update"`
}

Component represents an updatable component

type Config

type Config struct {
	CheckInterval      time.Duration `json:"check_interval"`   // How often to check for updates
	AutoUpdate         bool          `json:"auto_update"`      // Enable automatic updates
	AutoUpdateTime     string        `json:"auto_update_time"` // Time to apply auto-updates (e.g., "03:00")
	IncludePrereleases bool          `json:"include_prereleases"`
	DataPath           string        `json:"data_path"`            // Where to store downloaded updates
	GitHubToken        string        `json:"github_token"`         // GitHub token for private repos
	ShutdownTimeout    time.Duration `json:"shutdown_timeout"`     // How long to wait for graceful shutdown
	HealthCheckURL     string        `json:"health_check_url"`     // URL to check after restart
	HealthCheckTimeout time.Duration `json:"health_check_timeout"` // How long to wait for health check
	MinDiskSpace       int64         `json:"min_disk_space"`       // Minimum free disk space in bytes
}

Config holds updater configuration

type GitHubAsset

type GitHubAsset struct {
	Name               string `json:"name"`
	BrowserDownloadURL string `json:"browser_download_url"`
	Size               int64  `json:"size"`
	ContentType        string `json:"content_type"`
}

GitHubAsset represents a release asset

type GitHubRelease

type GitHubRelease struct {
	TagName     string        `json:"tag_name"`
	Name        string        `json:"name"`
	Prerelease  bool          `json:"prerelease"`
	Draft       bool          `json:"draft"`
	PublishedAt time.Time     `json:"published_at"`
	Assets      []GitHubAsset `json:"assets"`
}

GitHubRelease represents a GitHub release API response

type Launcher

type Launcher struct {
	// contains filtered or unexported fields
}

Launcher manages the NVR process lifecycle It's responsible for starting, stopping, and restarting the main NVR process

func NewLauncher

func NewLauncher(binaryPath string, args []string, logger *slog.Logger) *Launcher

NewLauncher creates a new launcher

func (*Launcher) GetPID

func (l *Launcher) GetPID() int

GetPID returns the PID of the running process, or 0 if not running

func (*Launcher) IsRunning

func (l *Launcher) IsRunning() bool

IsRunning returns whether the NVR process is running

func (*Launcher) Restart

func (l *Launcher) Restart()

Restart requests a restart of the NVR process

func (*Launcher) Run

func (l *Launcher) Run(ctx context.Context) error

Run starts and manages the NVR process This should be called from the main entrypoint

func (*Launcher) Stop

func (l *Launcher) Stop()

Stop requests a full shutdown

type UpdateStatus

type UpdateStatus struct {
	Component   string    `json:"component"`
	Status      string    `json:"status"` // checking, downloading, extracting, installing, complete, error
	Progress    float64   `json:"progress"`
	Message     string    `json:"message"`
	StartedAt   time.Time `json:"started_at"`
	CompletedAt time.Time `json:"completed_at,omitempty"`
	Error       string    `json:"error,omitempty"`
}

UpdateStatus represents the current update status

type Updater

type Updater struct {
	// contains filtered or unexported fields
}

Updater manages component updates

func NewUpdater

func NewUpdater(config Config, logger *slog.Logger) *Updater

NewUpdater creates a new updater instance

func (*Updater) CheckUpdate

func (u *Updater) CheckUpdate(ctx context.Context, componentName string) error

CheckUpdate checks for updates for a specific component

func (*Updater) CleanupOldBackups added in v0.0.21

func (u *Updater) CleanupOldBackups(maxAge time.Duration) error

CleanupOldBackups removes backups older than the specified duration

func (*Updater) GetAllUpdateStatus

func (u *Updater) GetAllUpdateStatus() map[string]*UpdateStatus

GetAllUpdateStatus returns status for all components

func (*Updater) GetBackups added in v0.0.21

func (u *Updater) GetBackups() map[string]*BackupInfo

GetBackups returns available backups for all components

func (*Updater) GetComponents

func (u *Updater) GetComponents() []Component

GetComponents returns all registered components

func (*Updater) GetPendingUpdates

func (u *Updater) GetPendingUpdates() []Component

GetPendingUpdates returns components that have updates available

func (*Updater) GetUpdateStatus

func (u *Updater) GetUpdateStatus(componentName string) *UpdateStatus

GetUpdateStatus returns the current update status for a component

func (*Updater) HealthCheck added in v0.0.21

func (u *Updater) HealthCheck(ctx context.Context) error

HealthCheck verifies the system is healthy after an update

func (*Updater) NeedsRestart

func (u *Updater) NeedsRestart() bool

NeedsRestart returns true if any component was updated and needs a restart

func (*Updater) RegisterComponent

func (u *Updater) RegisterComponent(c Component)

RegisterComponent registers a component for update tracking

func (*Updater) Rollback added in v0.0.21

func (u *Updater) Rollback(ctx context.Context, componentName string) error

Rollback restores a component from its backup

func (*Updater) SetGitHubToken

func (u *Updater) SetGitHubToken(token string)

SetGitHubToken updates the GitHub token dynamically

func (*Updater) SetOnRestartNeeded

func (u *Updater) SetOnRestartNeeded(fn func())

SetOnRestartNeeded sets the callback for when a restart is needed after updates

func (*Updater) SetOnUpdateAvailable

func (u *Updater) SetOnUpdateAvailable(fn func(component, currentVersion, latestVersion string))

SetOnUpdateAvailable sets the callback for when updates are available

func (*Updater) SetOnUpdateComplete

func (u *Updater) SetOnUpdateComplete(fn func(component, version string))

SetOnUpdateComplete sets the callback for when an update completes

func (*Updater) Start

func (u *Updater) Start(ctx context.Context) error

Start begins the update checking loop

func (*Updater) Stop

func (u *Updater) Stop()

Stop stops the updater

func (*Updater) Update

func (u *Updater) Update(ctx context.Context, componentName string) error

Update downloads and installs an update for a component with atomic staging and rollback support

func (*Updater) UpdateAll

func (u *Updater) UpdateAll(ctx context.Context) error

UpdateAll updates all components that have updates available

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL