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 48 hours old, and never while an update, a backup or an app operation runs. It starts exactly the update the dashboard's button starts, 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.
Four 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.
Index ¶
Constants ¶
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 and the update was not started: that is not a failed attempt, and the next check tries again.
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 ¶
This section is empty.
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
// 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)
// 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.
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 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"`
}
State is autoupdate.json.