Documentation
¶
Overview ¶
Package selfupdate updates a binary install from the UI: download the release asset, check checksums.txt and its ed25519 signature, probe the new binary, swap it in keeping the old one, restart, and roll back when the new one does not start. Containers, read-only installs and open ports without auth get the commands to run instead.
Index ¶
Constants ¶
const ( PhaseIdle = "idle" PhaseDownloading = "downloading" PhaseVerifying = "verifying" PhaseInstalling = "installing" PhaseRestarting = "restarting" PhaseDone = "done" PhaseFailed = "failed" PhaseRolledBack = "rolled_back" PhaseRestartRequired = "restart_required" )
Phases of State.
const ( ModeSelf = "self" // the button: download, verify, replace, restart ModeManual = "manual" // no button: the state carries commands to copy ModeOff = "off" // nothing to offer )
Modes of GET /api/update.
const ( InstallBinary = "binary" InstallDocker = "docker" InstallKubernetes = "kubernetes" )
Install kinds.
const ( SettingAuto = "auto" // self when safe: a container, a read-only dir or an open port without auth give manual SettingOn = "on" // also self on an open port without auth SettingOff = "off" // no update from the UI )
Setting values of update.self_update.
Variables ¶
var ( ErrBusy = errors.New("an update is already running") ErrNotLatest = errors.New("only the latest release can be installed") ErrNotAllowed = errors.New("update from the UI is not allowed") )
Errors of Start, mapped to HTTP codes by the API.
Functions ¶
func Boot ¶
Boot runs first in main. It reads the state an update left next to the binary: a first start of the new version keeps its output (for the rolled_back log) and is rolled back by Exit until Ready; a start that finds the last start of this version never got ready rolls back at once. The returned writer is where the log goes.
func Exit ¶
func Exit(code int)
Exit replaces os.Exit on start-up failures: a post-update boot that has not served yet restores the previous binary and database and runs it.
func LoopbackOnly ¶
LoopbackOnly reports whether a listen address takes local connections only. ":8000" and "0.0.0.0:8000" listen on every interface.
func Ready ¶
func Ready()
Ready marks a post-update boot as good: the state turns done and the database copy goes. Call it once the server serves.
func Reexec ¶
func Reexec()
Reexec runs the binary in place of this process (the new one after a swap).
func Restarting ¶
func Restarting() bool
Restarting reports that an update asked for a restart: main calls Reexec once everything is closed.
Types ¶
type Command ¶
type Command struct {
ID string `json:"id"`
Label string `json:"label"`
Command string `json:"command"`
}
Command is one line the user copies for a manual update.
type Config ¶
type Config struct {
Checker *updates.Checker // nil: the update check is off
Setting string // update.self_update
AuthOn bool
HTTPAddr string
DSN string
DB *sql.DB
Broadcast func(State) // sends update.progress; may be nil
Restart func() // stops the app so main re-execs; may be nil
}
Config wires an Updater.
type Facts ¶
type Facts struct {
Version string // running version, "dev" for a build without one
Release bool // Version is a release version
CheckOn bool // update_check.enabled
Setting string // update.self_update
AuthOn bool
HTTPAddr string
GOOS string
Exe string // resolved path of the running binary
Container string // "", InstallDocker or InstallKubernetes
Writable bool // the binary's dir takes a new file
}
Facts are what the mode is decided from. Detect fills them for the running process; tests build them by hand.
type Info ¶
type Info struct {
Current string `json:"current"`
Latest string `json:"latest"`
Available bool `json:"available"`
URL string `json:"url"`
Notes string `json:"notes"`
CheckedAt *time.Time `json:"checked_at"`
CheckEnabled bool `json:"check_enabled"`
Mode string `json:"mode"`
Reason string `json:"reason"`
Install string `json:"install"`
OS string `json:"os"`
Commands []Command `json:"commands"`
MemoryDB bool `json:"memory_db"`
RestartManual bool `json:"restart_manual"`
State State `json:"state"`
}
Info is the body of GET /api/update.
type State ¶
type State struct {
Phase string `json:"phase"`
Version string `json:"version"`
Previous string `json:"previous"`
FailedStep string `json:"failed_step"`
Bytes int64 `json:"bytes"`
Total int64 `json:"total"`
Error string `json:"error"`
Log string `json:"log"`
UpdatedAt *time.Time `json:"updated_at"`
}
State is the progress of an update, sent to the UI as is.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater runs one update at a time.
func (*Updater) CheckNow ¶
CheckNow asks GitHub at once, at most once a minute; wait > 0 is how long until the next check is allowed.