Documentation
¶
Overview ¶
Package autoupdate installs new ReCasaOS releases by itself, for an owner who turned it on: at night, inside a window of the box's local time, once a release is 24 hours old, and never while an update, a backup or an app operation runs. When the latest release is younger than that, it installs the newest one that is old enough, so a box is not kept back by releases that come out more than once in 24 hours. It starts the update the dashboard's button starts, for that release, and keeps its choice and its last attempt in autoupdate.json for the dashboard. An attempt that fails is tried once more the next night; after a second failure that release is paused until the owner resumes it or a newer one comes out.
Five environment variables are for the install check only, never for a box: CASAOS_AUTOUPDATE_START_DELAY and CASAOS_AUTOUPDATE_INTERVAL (Go durations, e.g. 0s) replace the random start delay and the hour between checks, and CASAOS_AUTOUPDATE_VERSION_URL and CASAOS_AUTOUPDATE_INSTALLER_URL, read by the update button's own code in service, replace version.json and install.sh; with the latter set, CASAOS_INSTALLER_TEST_PUBKEY adds a key that the installer's signature may be made with.
Index ¶
Constants ¶
const FolderSync = "folder-sync"
FolderSync is the name a folder sync in progress is listed under: AppManagement names it after its task, free text that is no app name and would be shown as an invalid one.
const (
// StateFile holds the choice, the window and the last attempt (root, 0600).
StateFile = "/var/lib/casaos/autoupdate.json"
)
Variables ¶
var Default = New("/")
Default is the box's own: the API answers from it and main runs its checks.
var ErrBusy = errors.New("the box is being changed by something else")
ErrBusy is what Start returns, wrapped, when something else is changing the box, or the release's installer could not be downloaded, and the update was not started: that is not a failed attempt, and the next check tries again.
var ErrRefused = errors.New("the release's installer was refused")
ErrRefused is what Start returns, wrapped, when the release's installer failed its signature or release check: a failed attempt, told to the owner as such (result "refused").
var ErrWindow = errors.New("window_start and window_end are HH:MM, local time, at least an hour apart")
ErrWindow is a window_start or window_end that is not HH:MM, or a window shorter than an hour.
Functions ¶
func OperationNames ¶ added in v0.4.117
OperationNames is what each operation is named after for the owner: its app, or FolderSync.
Types ¶
type AutoUpdate ¶
type AutoUpdate struct {
// Root is where autoupdate.json is kept: "/" on a box, a temporary
// directory in tests.
Root string
Now func() time.Time
// Current is the installed release, read as the update button reads it.
Current func() string
// Releases and Start are the update button's: main sets them to
// service.MyService.Casa() and System().UpdateSystemVersion, the detached
// casaos-update unit, its installer and its log.
Releases Releases
Start func(version string) error
// Settled, when set, returns the newest release published before the given
// time: what to install while the latest is under 24 hours old. main sets it
// to service.SettledCasaosVersion, and Start to the update of that release.
Settled func(before time.Time) model.Version
// Command runs a program and returns its standard output: systemctl.
Command func(name string, args ...string) ([]byte, error)
// AppsBusy reports whether AppManagement lists an operation in progress,
// or did not answer.
AppsBusy func(ctx context.Context) bool
// Busy, when set, reports whether something else is changing the box: a
// package update, an update of Docker, a package manager holding dpkg's lock.
// Nothing starts while it does.
Busy func() bool
// Notify, when set, hears how an attempt ended: succeeded, failed, or
// paused on its second failure. main sets it to the push alerts' hook.
Notify func(result, version string)
// Modules, when set, are updated by the night after ReCasaOS, and
// NotifyModules hears one sentence for each round that attempted one.
Modules Modules
NotifyModules func(sentence string)
// NotifyWithdrawn, when set, hears of an installed module at a version its catalogue withdrew, and
// answers whether a channel was told: a withdrawal told is not told again, one not told is next hour.
NotifyWithdrawn func(name, tag, reason string) bool
// contains filtered or unexported fields
}
AutoUpdate is the automatic updates of one box.
func New ¶
func New(root string) *AutoUpdate
New keeps autoupdate.json under root. Releases and Start are left to the caller.
func (*AutoUpdate) Check ¶
func (a *AutoUpdate) Check(ctx context.Context)
Check is one hourly pass: it settles the last attempt, then starts the latest release when every condition of decide holds. Nothing is read or asked when off or outside the window, and systemd and AppManagement only once everything else holds. A release held is not logged: the next check tries again while the window lasts. The modules come after, in a round that started no release. Before all of it, on or off, the installed modules at a version their catalogue withdrew are told (checkWithdrawn): that list is read every hour, off or not.
func (*AutoUpdate) Run ¶
func (a *AutoUpdate) Run(ctx context.Context)
Run settles the last attempt at once, since an update restarts the core, then checks after a random delay of up to ten minutes, which spreads the boxes a power cut restarted together, and every hour until ctx is done.
func (*AutoUpdate) Status ¶
func (a *AutoUpdate) Status() Status
Status reads version.json through the cache the dashboard's update row shares, and only when automatic updates are on. It asks neither systemd nor AppManagement: a release they hold shows as waiting until it starts.
type Change ¶
type Change struct {
Enabled *bool `json:"enabled"`
WindowStart *string `json:"window_start"`
WindowEnd *string `json:"window_end"`
Resume bool `json:"resume"` // clears the failures, and so a pause
}
Change is PUT /v1/sys/autoupdate's body: each field optional, others ignored.
type Last ¶
type Last struct {
Version string `json:"version"`
StartedAt time.Time `json:"started_at"`
Result string `json:"result"` // running, succeeded or failed
}
Last is the last automatic update started, in autoupdate.json and in the API.
type ModuleSeen ¶ added in v0.4.126
type ModuleSeen struct {
Tag string `json:"tag"`
FirstSeen time.Time `json:"first_seen"`
Tried time.Time `json:"tried,omitzero"`
}
ModuleSeen is the latest tag of a module, when this box first saw it in its catalogue, and when the night tried it (zero: not yet). A tag is tried once.
type ModuleUpdate ¶ added in v0.4.126
ModuleUpdate is an installed module and the later tag the catalogue has. Foreign is a module written outside ReCasaOS, and Allowed says the owner of the box lets the night update it: a foreign module that is not allowed is left alone.
type Modules ¶ added in v0.4.126
type Modules interface {
// List is the installed modules that have an update. An error, or a
// catalogue that cannot be read, is no list: nothing is changed.
List(ctx context.Context) ([]ModuleUpdate, error)
// Update updates a module to the tag List gave and waits for its job to end.
Update(ctx context.Context, name string) (Outcome, string)
// Withdrawn is the installed modules whose installed version the catalogue withdrew, with or without an
// update, from the catalogue the box already has (never the network).
Withdrawn(ctx context.Context) ([]Withdrawn, error)
}
Modules is what the night can do with the optional modules; main wires it to the service.
type Operation ¶ added in v0.4.67
Operation is an app operation in progress, as AppManagement lists it. Both fields are AppManagement's text: for the caller to validate before it shows or logs them.
func AppOperations ¶ added in v0.4.67
AppOperations asks AppManagement which app operations are in progress, the way the core reaches the other services: at the address it leaves in the runtime path, with this boot's secret. The list is empty (not nil) when nothing runs. An error is no answer: it could not be asked, or what it said is not the list, and a caller that must not act on a guess treats it as an operation in progress.
type Releases ¶
Releases reads version.json the way the update button does: service's CasaService, through its 20-minute cache or past it.
type State ¶
type State struct {
Enabled bool `json:"enabled"`
WindowStart string `json:"window_start"`
WindowEnd string `json:"window_end"`
Last *Last `json:"last,omitempty"`
Failures *Failures `json:"failures,omitempty"`
// Modules is what the night saw of each module's update, by name.
Modules map[string]ModuleSeen `json:"modules,omitempty"`
// Withdrawn is each installed module version withdrawn from the catalogue that was told, kept
// for good: a withdrawal lifted and made again is not told twice.
Withdrawn []ModuleTag `json:"withdrawn,omitempty"`
}
State is autoupdate.json.
type Status ¶
type Status struct {
Enabled bool `json:"enabled"`
Window Window `json:"window"`
State string `json:"state"` // off, up_to_date, waiting, updating or paused
Next *Next `json:"next"`
Last *Last `json:"last"`
}
Status is what GET and PUT /v1/sys/autoupdate answer in data.