updatehub

package
v0.0.0-...-746469e Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: Apache-2.0 Imports: 26 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// The system settings are the settings configured in the client-side and will be read-only
	SystemSettingsPath = "/etc/updatehub.conf"

	// The state change callback is executed twice each state
	// change. Once before the state handling and once after. Ex.:
	// <stateChangeCallbackPath> enter downloading
	// <stateChangeCallbackPath> leave downloading
	StateChangeCallbackPath = "/usr/share/updatehub/state-change-callback"

	// The error callback is executed whenever a error state is
	// handled. Ex.:
	// <errorCallbackPath> 'error_message'
	ErrorCallbackPath = "/usr/share/updatehub/error-callback"

	// The validate callback is executed whenever a successful
	// installation is booted.
	ValidateCallbackPath = "/usr/share/updatehub/validate-callback"

	// The rollback callback is executed whenever the agent boots
	// after an errored installation boot
	RollbackCallbackPath = "/usr/share/updatehub/rollback-callback"
)
View Source
const (
	// UpdateHubDummyState is a dummy state
	UpdateHubDummyState = iota
	// UpdateHubStateIdle is set when the agent is in the "idle" mode
	UpdateHubStateIdle
	// UpdateHubStatePoll is set when the agent is in the "polling" mode
	UpdateHubStatePoll
	// UpdateHubStateProbe is set when the agent is running a
	// "probeUpdate" procedure
	UpdateHubStateProbe
	// UpdateHubStateDownloading is set when the agent is downloading
	// an update
	UpdateHubStateDownloading
	// UpdateHubStateDownloaded is set when the agent finished
	// downloading an update
	UpdateHubStateDownloaded
	// UpdateHubStateInstalling is set when the agent is starting an
	// update installation
	UpdateHubStateInstalling
	// UpdateHubStateInstalled is set when the agent finished
	// installing an update
	UpdateHubStateInstalled
	// UpdateHubStateExit is set when the daemon is about to quit
	UpdateHubStateExit
	// UpdateHubStateError is set when an error occured on the agent
	UpdateHubStateError
	// UpdateHubStateRebooting is set when an error occured on the agent
	UpdateHubStateRebooting
)
View Source
const (
	// TransitionFlowUnchanged indicates that transition flow will remain unchanged
	TransitionFlowUnchanged = iota
	// TransitionFlowCancelled indicates that transition flow will be cancelled
	TransitionFlowCancelled
	// TransitionFlowPostponed indicates that transition flow will be postponed
	TransitionFlowPostponed
)

Variables

View Source
var DefaultSettings = Settings{
	PollingSettings: PollingSettings{
		PollingInterval: defaultPollingInterval,
		PollingEnabled:  true,
		PersistentPollingSettings: PersistentPollingSettings{
			LastPoll:             (time.Time{}).UTC(),
			FirstPoll:            (time.Time{}).UTC(),
			ExtraPollingInterval: 0,
			PollingRetries:       0,
			ProbeASAP:            false,
		},
	},

	StorageSettings: StorageSettings{
		ReadOnly:            false,
		RuntimeSettingsPath: "/var/lib/updatehub.conf",
	},

	UpdateSettings: UpdateSettings{
		DownloadDir:           "/tmp",
		SupportedInstallModes: []string{"dry-run", "copy", "flash", "imxkobs", "raw", "tarball", "ubifs"},
		PersistentUpdateSettings: PersistentUpdateSettings{
			UpgradeToInstallation: -1,
		},
	},

	NetworkSettings: NetworkSettings{
		ServerAddress: defaultServerAddress,
		ListenSocket:  "tcp://localhost:8080",
	},

	FirmwareSettings: FirmwareSettings{
		FirmwareMetadataPath: "/usr/share/updatehub",
	},
}
View Source
var ErrSha256sum = errors.New("sha256sum's don't match")

Functions

func GetIndexOfObjectToBeInstalled

func GetIndexOfObjectToBeInstalled(aii activeinactive.Interface, um *metadata.UpdateMetadata) (int, error)

GetIndexOfObjectToBeInstalled selects which object will be installed from the update metadata

func StateToString

func StateToString(status UpdateHubState) string

StateToString converts a "UpdateHubState" to string

Types

type BaseState

type BaseState struct {
	// contains filtered or unexported fields
}

BaseState is the state from which all others must do composition

func (*BaseState) ApiClient

func (b *BaseState) ApiClient() *client.ApiClient

ApiClient returns the apiClient

func (*BaseState) Cancel

func (b *BaseState) Cancel(ok bool, nextState State) bool

Cancel cancels a state if it is cancellable

func (*BaseState) ID

func (b *BaseState) ID() UpdateHubState

ID returns the state id

func (*BaseState) ToMap

func (state *BaseState) ToMap() map[string]interface{}

ToMap is for the State interface implementation

type CancellableState

type CancellableState struct {
	BaseState
	// contains filtered or unexported fields
}

func (*CancellableState) Cancel

func (cs *CancellableState) Cancel(ok bool, nextState State) bool

func (*CancellableState) Handle

func (cs *CancellableState) Handle(uh *UpdateHub) (State, bool)

func (*CancellableState) NextState

func (cs *CancellableState) NextState() State

func (*CancellableState) Stop

func (cs *CancellableState) Stop()

func (*CancellableState) Wait

func (cs *CancellableState) Wait()

type Controller

type Controller interface {
	ProbeUpdate(*client.ApiClient, int) (*metadata.UpdateMetadata, []byte, time.Duration, error)
	DownloadUpdate(*client.ApiClient, *metadata.UpdateMetadata, <-chan bool, chan<- int) error
	InstallUpdate(*metadata.UpdateMetadata, chan<- int) error
}

type Daemon

type Daemon struct {
	// contains filtered or unexported fields
}

func NewDaemon

func NewDaemon(uh *UpdateHub) *Daemon

func (*Daemon) Run

func (d *Daemon) Run() int

func (*Daemon) Stop

func (d *Daemon) Stop()

type DownloadedState

type DownloadedState struct {
	BaseState
	ReportableState
	// contains filtered or unexported fields
}

DownloadedState is the State interface implementation for the UpdateHubStateDownloaded

func NewDownloadedState

func NewDownloadedState(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata) *DownloadedState

NewDownloadedState creates a new DownloadedState

func (*DownloadedState) Handle

func (state *DownloadedState) Handle(uh *UpdateHub) (State, bool)

Handle for DownloadedState just returns a new installing state

func (*DownloadedState) ID

func (state *DownloadedState) ID() UpdateHubState

ID returns the state id

func (*DownloadedState) UpdateMetadata

func (state *DownloadedState) UpdateMetadata() *metadata.UpdateMetadata

UpdateMetadata is the ReportableState interface implementation

type DownloadingState

type DownloadingState struct {
	BaseState
	CancellableState
	ReportableState
	ProgressTracker
	// contains filtered or unexported fields
}

DownloadingState is the State interface implementation for the UpdateHubStateDownloading

func NewDownloadingState

func NewDownloadingState(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata, pti ProgressTracker) *DownloadingState

NewDownloadingState creates a new DownloadingState from a metadata.UpdateMetadata

func (*DownloadingState) Cancel

func (state *DownloadingState) Cancel(ok bool, nextState State) bool

Cancel cancels a state if it is cancellable

func (*DownloadingState) Handle

func (state *DownloadingState) Handle(uh *UpdateHub) (State, bool)

Handle for DownloadingState starts the objects downloads. It goes to the installing state if successfull. It goes back to the error state otherwise.

func (*DownloadingState) ID

func (state *DownloadingState) ID() UpdateHubState

ID returns the state id

func (*DownloadingState) ToMap

func (state *DownloadingState) ToMap() map[string]interface{}

ToMap is for the State interface implementation

func (*DownloadingState) UpdateMetadata

func (state *DownloadingState) UpdateMetadata() *metadata.UpdateMetadata

UpdateMetadata is the ReportableState interface implementation

type ErrorState

type ErrorState struct {
	BaseState

	ReportableState
	// contains filtered or unexported fields
}

ErrorState is the State interface implementation for the UpdateHubStateError

func (*ErrorState) Handle

func (state *ErrorState) Handle(uh *UpdateHub) (State, bool)

Handle for ErrorState calls "panic" if the error is fatal or triggers a poll state otherwise

func (*ErrorState) ToMap

func (state *ErrorState) ToMap() map[string]interface{}

ToMap is for the State interface implementation

func (*ErrorState) UpdateMetadata

func (state *ErrorState) UpdateMetadata() *metadata.UpdateMetadata

UpdateMetadata is the ReportableState interface implementation

type ExitState

type ExitState struct {
	BaseState
	// contains filtered or unexported fields
}

ExitState is the final state of the state machine

func NewExitState

func NewExitState(exitCode int) *ExitState

NewExitState creates a new ExitState

func (*ExitState) Handle

func (state *ExitState) Handle(uh *UpdateHub) (State, bool)

Handle for ExitState

type FirmwareSettings

type FirmwareSettings struct {
	FirmwareMetadataPath string `ini:"MetadataPath" json:"metadata-path"`
}

type IdleState

type IdleState struct {
	BaseState
	CancellableState
}

IdleState is the State interface implementation for the UpdateHubStateIdle

func NewIdleState

func NewIdleState() *IdleState

NewIdleState creates a new IdleState

func (*IdleState) Cancel

func (state *IdleState) Cancel(ok bool, nextState State) bool

Cancel cancels a state if it is cancellable

func (*IdleState) Handle

func (state *IdleState) Handle(uh *UpdateHub) (State, bool)

Handle for IdleState

func (*IdleState) ID

func (state *IdleState) ID() UpdateHubState

ID returns the state id

type InstalledState

type InstalledState struct {
	BaseState
	ReportableState
	// contains filtered or unexported fields
}

InstalledState is the State interface implementation for the UpdateHubStateInstalled

func NewInstalledState

func NewInstalledState(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata) *InstalledState

NewInstalledState creates a new InstalledState

func (*InstalledState) Handle

func (state *InstalledState) Handle(uh *UpdateHub) (State, bool)

Handle for InstalledState implements the installation process itself

func (*InstalledState) ID

func (state *InstalledState) ID() UpdateHubState

ID returns the state id

func (*InstalledState) UpdateMetadata

func (state *InstalledState) UpdateMetadata() *metadata.UpdateMetadata

UpdateMetadata is the ReportableState interface implementation

type InstallingState

type InstallingState struct {
	BaseState
	ReportableState
	ProgressTracker
	FileSystemBackend afero.Fs
	// contains filtered or unexported fields
}

InstallingState is the State interface implementation for the UpdateHubStateInstalling

func NewInstallingState

func NewInstallingState(
	apiClient *client.ApiClient,
	updateMetadata *metadata.UpdateMetadata,
	pti ProgressTracker,
	fsb afero.Fs) *InstallingState

NewInstallingState creates a new InstallingState

func (*InstallingState) Handle

func (state *InstallingState) Handle(uh *UpdateHub) (State, bool)

Handle for InstallingState implements the installation process itself

func (*InstallingState) ID

func (state *InstallingState) ID() UpdateHubState

ID returns the state id

func (*InstallingState) ToMap

func (state *InstallingState) ToMap() map[string]interface{}

ToMap is for the State interface implementation

func (*InstallingState) UpdateMetadata

func (state *InstallingState) UpdateMetadata() *metadata.UpdateMetadata

UpdateMetadata is the ReportableState interface implementation

type NetworkSettings

type NetworkSettings struct {
	ServerAddress string `ini:"ServerAddress" json:"server-address"`
	ListenSocket  string `ini:"ListenSocket" json:"listen-socket"`
}

type PersistentPollingSettings

type PersistentPollingSettings struct {
	LastPoll             time.Time     `ini:"LastPoll" json:"last-poll"`
	FirstPoll            time.Time     `ini:"FirstPoll" json:"first-poll"`
	ExtraPollingInterval time.Duration `ini:"ExtraInterval" json:"extra-interval"`
	PollingRetries       int           `ini:"Retries" json:"retries"`
	ProbeASAP            bool          `ini:"ProbeASAP" json:"probe-asap"`
}

type PersistentSettings

type PersistentSettings struct {
	PersistentPollingSettings `ini:"Polling"`
	PersistentUpdateSettings  `ini:"Update"`
}

type PersistentUpdateSettings

type PersistentUpdateSettings struct {
	UpgradeToInstallation int `ini:"UpgradeToInstallation" json:"upgrade-to-installation"`
}

type PollState

type PollState struct {
	BaseState
	CancellableState
	// contains filtered or unexported fields
}

PollState is the State interface implementation for the UpdateHubStatePoll

func NewPollState

func NewPollState(pollingInterval time.Duration) *PollState

NewPollState creates a new PollState

func (*PollState) Cancel

func (state *PollState) Cancel(ok bool, nextState State) bool

Cancel cancels a state if it is cancellable

func (*PollState) Handle

func (state *PollState) Handle(uh *UpdateHub) (State, bool)

Handle for PollState encapsulates the polling logic

func (*PollState) ID

func (state *PollState) ID() UpdateHubState

ID returns the state id

type PollingSettings

type PollingSettings struct {
	PollingInterval           time.Duration `ini:"Interval,omitempty" json:"interval,omitempty"`
	PollingEnabled            bool          `ini:"Enabled,omitempty" json:"enabled,omitempty"`
	PersistentPollingSettings `ini:"Polling"`
}

type ProbeState

type ProbeState struct {
	BaseState
	CancellableState

	ProbeResponseReady chan bool
	// contains filtered or unexported fields
}

ProbeState is the State interface implementation for the UpdateHubStateProbe

func NewProbeState

func NewProbeState(apiClient *client.ApiClient) *ProbeState

NewProbeState creates a new ProbeState

func (*ProbeState) Cancel

func (state *ProbeState) Cancel(ok bool, nextState State) bool

Cancel cancels a state if it is cancellable

func (*ProbeState) Handle

func (state *ProbeState) Handle(uh *UpdateHub) (State, bool)

Handle for ProbeState executes a ProbeUpdate procedure and proceed to download the update if there is one. It goes back to the polling state otherwise.

func (*ProbeState) ID

func (state *ProbeState) ID() UpdateHubState

ID returns the state id

func (*ProbeState) ProbeResponse

func (state *ProbeState) ProbeResponse() (*metadata.UpdateMetadata, time.Duration)

type ProgressTracker

type ProgressTracker interface {
	SetProgress(progress int)
	GetProgress() int
}

ProgressTracker will define which way the progress is kept

type ProgressTrackerImpl

type ProgressTrackerImpl struct {
	// contains filtered or unexported fields
}

ProgressTrackerImpl is for the ProgressTracker interface implementation

func (*ProgressTrackerImpl) GetProgress

func (pti *ProgressTrackerImpl) GetProgress() int

GetProgress is for the ProgressTracker interface implementation

func (*ProgressTrackerImpl) SetProgress

func (pti *ProgressTrackerImpl) SetProgress(progress int)

SetProgress is for the ProgressTracker interface implementation

type RebootingState

type RebootingState struct {
	BaseState
	ReportableState
	// contains filtered or unexported fields
}

RebootingState is the State interface implementation for the UpdateHubStateRebooting

func NewRebootingState

func NewRebootingState(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata) *RebootingState

NewRebootingState creates a new RebootingState

func (*RebootingState) Handle

func (state *RebootingState) Handle(uh *UpdateHub) (State, bool)

Handle for RebootingState implements the installation process itself

func (*RebootingState) ID

func (state *RebootingState) ID() UpdateHubState

ID returns the state id

func (*RebootingState) UpdateMetadata

func (state *RebootingState) UpdateMetadata() *metadata.UpdateMetadata

UpdateMetadata is the ReportableState interface implementation

type ReportableState

type ReportableState interface {
	UpdateMetadata() *metadata.UpdateMetadata
}

ReportableState interface describes the necessary operations for a State to be reportable

type Settings

type Settings struct {
	PollingSettings  `ini:"Polling" json:"polling"`
	StorageSettings  `ini:"Storage" json:"storage"`
	UpdateSettings   `ini:"Update" json:"update"`
	NetworkSettings  `ini:"Network" json:"network"`
	FirmwareSettings `ini:"Firmware" json:"firmware"`
}

func LoadSettings

func LoadSettings(r io.Reader) (*Settings, error)

func (*Settings) Save

func (s *Settings) Save(fs afero.Fs) error

func (*Settings) ToString

func (s *Settings) ToString() string

type Sha256Checker

type Sha256Checker interface {
	CheckDownloadedObjectSha256sum(fsBackend afero.Fs, downloadDir string, expectedSha256sum string) (bool, error)
}

type Sha256CheckerImpl

type Sha256CheckerImpl struct {
}

func (*Sha256CheckerImpl) CheckDownloadedObjectSha256sum

func (s *Sha256CheckerImpl) CheckDownloadedObjectSha256sum(fsBackend afero.Fs, downloadDir string, expectedSha256sum string) (bool, error)

type State

type State interface {
	ID() UpdateHubState
	Handle(*UpdateHub) (State, bool) // Handle implements the behavior when the State is set
	Cancel(bool, State) bool
	ToMap() map[string]interface{}
	ApiClient() *client.ApiClient
}

State interface describes the necessary operations for a State

func NewErrorState

func NewErrorState(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata, err UpdateHubErrorReporter) State

NewErrorState creates a new ErrorState from a UpdateHubErrorReporter

type StorageSettings

type StorageSettings struct {
	ReadOnly            bool   `ini:"ReadOnly" json:"read-only"`
	RuntimeSettingsPath string `ini:"RuntimeSettingsPath" json:"runtime-settings-path"`
}

type TransitionFlow

type TransitionFlow int

TransitionFlow indicates the transition flow of state change callback

func DetermineTransitionFlow

func DetermineTransitionFlow(output []byte) (TransitionFlow, interface{})

DetermineTransitionFlow determines transition flow for state change callback

type UpdateHub

type UpdateHub struct {
	Controller
	CopyBackend copy.Interface `json:"-"`

	Version          string
	Settings         *Settings
	Store            afero.Fs
	FirmwareMetadata metadata.FirmwareMetadata
	PublicKey        *rsa.PublicKey
	TimeStep         time.Duration
	Updater          client.Updater
	Reporter         client.Reporter
	IgnoreProbeASAP  bool

	ActiveInactiveBackend activeinactive.Interface

	StateChangeCallbackPath   string
	ErrorCallbackPath         string
	ValidateCallbackPath      string
	RollbackCallbackPath      string
	InstallIfDifferentBackend installifdifferent.Interface
	Sha256Checker
	utils.Rebooter
	utils.CmdLineExecuter

	DefaultApiClient *client.ApiClient
	// contains filtered or unexported fields
}

func NewUpdateHub

func NewUpdateHub(
	gitversion string,
	stateChangeCallbackPath string,
	errorCallbackPath string,
	validateCallbackPath string,
	rollbackCallbackPath string,
	fs afero.Fs,
	fm metadata.FirmwareMetadata,
	pubKey *rsa.PublicKey,
	initialState State,
	settings *Settings,
	DefaultApiClient *client.ApiClient) *UpdateHub

func (*UpdateHub) Cancel

func (uh *UpdateHub) Cancel(nextState State)

func (*UpdateHub) DownloadUpdate

func (uh *UpdateHub) DownloadUpdate(apiClient *client.ApiClient, updateMetadata *metadata.UpdateMetadata, cancel <-chan bool, progressChan chan<- int) error

it is recommended to use a buffered channel for "progressChan" to ensure no progress event is lost

func (*UpdateHub) GetState

func (uh *UpdateHub) GetState() State

func (*UpdateHub) InstallUpdate

func (uh *UpdateHub) InstallUpdate(updateMetadata *metadata.UpdateMetadata, progressChan chan<- int) error

it is recommended to use a buffered channel for "progressChan" to ensure no progress event is lost

func (*UpdateHub) ProbeUpdate

func (uh *UpdateHub) ProbeUpdate(apiClient *client.ApiClient, retries int) (*metadata.UpdateMetadata, []byte, time.Duration, error)

func (*UpdateHub) ProcessCurrentState

func (uh *UpdateHub) ProcessCurrentState() State

func (*UpdateHub) ReportCurrentState

func (uh *UpdateHub) ReportCurrentState() error

func (*UpdateHub) SetState

func (uh *UpdateHub) SetState(state State)

func (*UpdateHub) Start

func (uh *UpdateHub) Start()

Start starts the updatehub

type UpdateHubError

type UpdateHubError struct {
	// contains filtered or unexported fields
}

func (*UpdateHubError) Cause

func (e *UpdateHubError) Cause() error

func (*UpdateHubError) Error

func (e *UpdateHubError) Error() string

func (*UpdateHubError) IsFatal

func (e *UpdateHubError) IsFatal() bool

type UpdateHubErrorReporter

type UpdateHubErrorReporter interface {
	Cause() error
	IsFatal() bool
	error
}

func NewFatalError

func NewFatalError(err error) UpdateHubErrorReporter

func NewTransientError

func NewTransientError(err error) UpdateHubErrorReporter

type UpdateHubState

type UpdateHubState int

UpdateHubState holds the possible states for the agent

type UpdateSettings

type UpdateSettings struct {
	DownloadDir              string   `ini:"DownloadDir" json:"download-dir"`
	SupportedInstallModes    []string `ini:"SupportedInstallModes" json:"supported-install-modes"`
	PersistentUpdateSettings `ini:"Update"`
}

Jump to

Keyboard shortcuts

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