selfupdate

package
v0.16.124 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package selfupdate keeps the programs of a machine connected to a hub the same as the ones the hub serves (<hub>/dl/manifest.json, the file install.sh downloads from). It compares the SHA-256 of the installed files with the manifest, downloads what differs, checks the download against the manifest and puts it in place with a rename, so a running program is never cut. Then the caller restarts what it replaced.

The files are compared, not version numbers: the hub's binaries may all be "dev" builds, and a machine must still get the hub's latest ones.

Index

Constants

View Source
const (
	// DefaultInterval is the time between checks.
	DefaultInterval = time.Hour
	// FirstDelay is the wait before the first check after a start: an update right after one would restart the
	// program before the page has had a look at it.
	FirstDelay = 2 * time.Minute
)

Variables

View Source
var ErrBusy = errors.New("an update is already going on")

ErrBusy: an update is already going on.

View Source
var ErrManual = errors.New("this machine cannot replace its own programs: run the update command")

ErrManual: this machine cannot replace its own programs; the command is needed.

Functions

This section is empty.

Types

type File

type File struct {
	Name string
	Path string
	// Optional: a hub that does not serve it is no error, and a machine without it gets it.
	Optional bool
}

File is one installed program: its name in the manifest ("agent", "runtime") and where it is.

type Status

type Status struct {
	// Mode is "auto" when this machine can replace its programs itself, "manual" when it needs Command.
	Mode string `json:"mode"`
	// Checked says whether a check has been made since the start.
	Checked bool `json:"checked"`
	// UpToDate: the installed programs are the hub's (meaningful once Checked).
	UpToDate bool `json:"upToDate"`
	// Applying: an update is being downloaded and put in place.
	Applying bool `json:"applying"`
	// Version is what the hub calls its programs (may be "dev").
	Version string `json:"version,omitempty"`
	// CheckedAt is the time of the last check, RFC 3339.
	CheckedAt string `json:"checkedAt,omitempty"`
	// Error is the last check's or update's failure, for the person.
	Error string `json:"error,omitempty"`
	// Command updates this machine from its shell (run where it was installed).
	Command string `json:"command"`
}

Status is what the page is told.

type Updater

type Updater struct {
	HubURL string
	Files  []File
	GOOS   string
	GOARCH string
	// Auto makes Run apply an update by itself; otherwise it only checks.
	Auto bool
	// Sudo: the install command needs root (a system install).
	Sudo bool
	// Client makes the requests; nil means one that honours the proxy environment.
	Client *http.Client
	// Interval is the time between checks; zero means DefaultInterval.
	Interval time.Duration
	// Applied runs after the files were replaced, with the names of those replaced (the caller restarts them).
	Applied func(names []string)
	// Log gets one line per failure; may be nil.
	Log func(msg string, err error)
	// contains filtered or unexported fields
}

Updater checks and applies. Set HubURL, Files, GOOS and GOARCH.

func (*Updater) Apply

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

Apply checks and replaces what differs; Applied runs when something was replaced.

func (*Updater) Check

func (u *Updater) Check(ctx context.Context) (Status, error)

Check compares the installed files with the hub's and records the answer.

func (*Updater) Command

func (u *Updater) Command() string

Command is the shell command that updates this machine by the hub's installer.

func (*Updater) Run

func (u *Updater) Run(ctx context.Context)

Run checks after FirstDelay and then every Interval until ctx ends, applying what it finds when Auto. Start it with go.

func (*Updater) Status

func (u *Updater) Status() Status

Status is the last answer.

func (*Updater) Writable

func (u *Updater) Writable() bool

Writable says whether every file's folder lets this process put a new file there (and so replace the file).

Jump to

Keyboard shortcuts

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