autoupdate

package
v0.4.88 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 20 Imported by: ? 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 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

View Source
const (
	// StateFile holds the choice, the window and the last attempt (root, 0600).
	StateFile = "/var/lib/casaos/autoupdate.json"
)

Variables

View Source
var Default = New("/")

Default is the box's own: the API answers from it and main runs its checks.

View Source
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.

View Source
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.

func (*AutoUpdate) Update

func (a *AutoUpdate) Update(c Change) (Status, error)

Update applies c, rewriting a malformed autoupdate.json, and answers the new status. A window that is not one is ErrWindow, and nothing is written.

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 Failures

type Failures struct {
	Version string `json:"version"`
	Count   int    `json:"count"`
}

Failures counts the failed attempts at one release; the second pauses it.

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 Next

type Next struct {
	Version   string    `json:"version"`
	NotBefore time.Time `json:"not_before"`
}

Next is the release aimed at and the earliest time it may start.

type Operation added in v0.4.67

type Operation struct {
	App  string `json:"app"`
	Kind string `json:"kind"`
}

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

func AppOperations(ctx context.Context, runtimePath string) ([]Operation, error)

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

type Releases interface {
	GetCasaosVersion() model.Version
	FetchCasaosVersion() model.Version
}

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.

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.

type Window

type Window struct {
	Start string `json:"start"`
	End   string `json:"end"`
}

Window is the nightly window, HH:MM in the box's local time.

Jump to

Keyboard shortcuts

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