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 ¶
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 ¶
var ErrBusy = errors.New("an update is already going on")
ErrBusy: an update is already going on.
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 ¶
Apply checks and replaces what differs; Applied runs when something was replaced.
func (*Updater) Command ¶
Command is the shell command that updates this machine by the hub's installer.