Documentation ¶
Overview ¶
Copyright 2020 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2020 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2019 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2020 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2019 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2020 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2020 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2020 Northern.tech AS
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- func DoStandaloneCommit(device *dev.DeviceManager, stateExec statescript.Executor) error
- func DoStandaloneInstall(device *dev.DeviceManager, updateURI string, clientConfig client.Config, ...) error
- func DoStandaloneRollback(device *dev.DeviceManager, stateExec statescript.Executor) error
- func Min(a, b int) int
- func NewFatalError(err error) menderError
- func NewTransientError(err error) menderError
- func NewUpdateState(id datastore.MenderState, t Transition, u *datastore.UpdateInfo) *updateState
- func NewWaitState(id datastore.MenderState, t Transition) *waitState
- func RemoveStateData(store store.Store) error
- func StateStatus(m datastore.MenderState) string
- type AuthManager
- type AuthManagerConfig
- type Controller
- type DeploymentHook
- type DeploymentJSONFormatter
- type DeploymentLogManager
- type FileLogger
- type Mender
- func (m *Mender) Authorize() menderError
- func (m *Mender) Bootstrap() menderError
- func (m *Mender) CheckScriptsCompatibility() error
- func (m *Mender) CheckUpdate() (*datastore.UpdateInfo, menderError)
- func (m *Mender) FetchUpdate(url string) (io.ReadCloser, int64, error)
- func (m *Mender) ForceBootstrap()
- func (m *Mender) GetCurrentState() State
- func (m *Mender) GetInventoryPollInterval() time.Duration
- func (m *Mender) GetRetryPollInterval() time.Duration
- func (m *Mender) GetScriptExecutor() statescript.Executor
- func (m *Mender) GetUpdatePollInterval() time.Duration
- func (m *Mender) InventoryRefresh() error
- func (m *Mender) IsAuthorized() bool
- func (m *Mender) NewStatusReportWrapper(updateId string, stateId datastore.MenderState) *client.StatusReportWrapper
- func (m *Mender) ReportUpdateStatus(update *datastore.UpdateInfo, status string) menderError
- func (m *Mender) SetNextState(s State)
- func (m *Mender) TransitionState(to State, ctx *StateContext) (State, bool)
- func (m *Mender) UploadLog(update *datastore.UpdateInfo, logs []byte) menderError
- type MenderAuthManager
- func (m *MenderAuthManager) AuthToken() (client.AuthToken, error)
- func (m *MenderAuthManager) GenerateKey() error
- func (m *MenderAuthManager) HasKey() bool
- func (m *MenderAuthManager) IsAuthorized() bool
- func (m *MenderAuthManager) MakeAuthRequest() (*client.AuthRequest, error)
- func (m *MenderAuthManager) RecvAuthResponse(data []byte) error
- func (m *MenderAuthManager) RemoveAuthToken() error
- type MenderDaemon
- type MenderError
- type MenderPieces
- type State
- func NewAuthorizeWaitState() State
- func NewCheckWaitState() State
- func NewErrorState(err menderError) State
- func NewFetchStoreRetryState(from State, update *datastore.UpdateInfo, err error) State
- func NewReportErrorState(update *datastore.UpdateInfo, status string) State
- func NewUpdateAfterCommitState(update *datastore.UpdateInfo) State
- func NewUpdateAfterFirstCommitState(update *datastore.UpdateInfo) State
- func NewUpdateAfterRebootState(update *datastore.UpdateInfo) State
- func NewUpdateAfterRollbackRebootState(update *datastore.UpdateInfo) State
- func NewUpdateAfterStoreState(update *datastore.UpdateInfo) State
- func NewUpdateCleanupState(update *datastore.UpdateInfo, status string) State
- func NewUpdateCommitState(update *datastore.UpdateInfo) State
- func NewUpdateErrorState(err menderError, update *datastore.UpdateInfo) State
- func NewUpdateFetchState(update *datastore.UpdateInfo) State
- func NewUpdateInstallState(update *datastore.UpdateInfo) State
- func NewUpdatePreCommitStatusReportRetryState(returnToState State, reportTries int) State
- func NewUpdateRebootState(update *datastore.UpdateInfo) State
- func NewUpdateRollbackRebootState(update *datastore.UpdateInfo) State
- func NewUpdateRollbackState(update *datastore.UpdateInfo) State
- func NewUpdateStatusReportRetryState(reportState State, update *datastore.UpdateInfo, status string, tries int) State
- func NewUpdateStatusReportState(update *datastore.UpdateInfo, status string) State
- func NewUpdateStoreState(in io.ReadCloser, update *datastore.UpdateInfo) State
- func NewUpdateVerifyRebootState(update *datastore.UpdateInfo) State
- func NewUpdateVerifyRollbackRebootState(update *datastore.UpdateInfo) State
- type StateCollection
- type StateContext
- type StateRunner
- type Transition
- func (t Transition) Enter(exec statescript.Executor, report *client.StatusReportWrapper, ...) error
- func (t Transition) Error(exec statescript.Executor, report *client.StatusReportWrapper) error
- func (t Transition) IsToError() bool
- func (t Transition) Leave(exec statescript.Executor, report *client.StatusReportWrapper, ...) error
- func (t Transition) String() string
- type UpdateState
- type WaitState
Constants ¶
This section is empty.
Variables ¶
var ( ErrLoggerNotInitialized = errors.New("logger not initialized") ErrNotEnoughSpaceForLogs = errors.New("not enough space for storing logs") )
error messages
var States = StateCollection{ Authorize: &authorizeState{ baseState{ id: datastore.MenderStateAuthorize, t: ToSync, }, }, AuthorizeWait: NewAuthorizeWaitState().(*authorizeWaitState), CheckWait: NewCheckWaitState().(*checkWaitState), Final: &finalState{ baseState{ id: datastore.MenderStateDone, t: ToNone, }, }, Init: &initState{ baseState{ id: datastore.MenderStateInit, t: ToNone, }, }, Idle: &idleState{ baseState{ id: datastore.MenderStateIdle, t: ToIdle, }, }, InventoryUpdate: &inventoryUpdateState{ baseState{ id: datastore.MenderStateInventoryUpdate, t: ToSync, }, }, UpdateCheck: &updateCheckState{ baseState{ id: datastore.MenderStateUpdateCheck, t: ToSync, }, }, }
Exposed state variables.
Functions ¶
func DoStandaloneCommit ¶
func DoStandaloneCommit(device *dev.DeviceManager, stateExec statescript.Executor) error
func DoStandaloneInstall ¶
func DoStandaloneInstall(device *dev.DeviceManager, updateURI string, clientConfig client.Config, vKey []byte, stateExec statescript.Executor) error
This will be run manually from command line ONLY
func DoStandaloneRollback ¶
func DoStandaloneRollback(device *dev.DeviceManager, stateExec statescript.Executor) error
func NewFatalError ¶
func NewFatalError(err error) menderError
Create a new fatal error. Fatal errors will be reported back to the server.
func NewTransientError ¶
func NewTransientError(err error) menderError
Create a new transient error. Transient errors will normally not be reported back to the server, unless they persist long enough for the client to give up.
func NewUpdateState ¶
func NewUpdateState(id datastore.MenderState, t Transition, u *datastore.UpdateInfo) *updateState
func NewWaitState ¶
func NewWaitState(id datastore.MenderState, t Transition) *waitState
func RemoveStateData ¶
func StateStatus ¶
func StateStatus(m datastore.MenderState) string
Types ¶
type AuthManager ¶
type AuthManager interface { // returns true if authorization data is current and valid IsAuthorized() bool // returns device's authorization token AuthToken() (client.AuthToken, error) // removes authentication token RemoveAuthToken() error // check if device key is available HasKey() bool // generate device key (will overwrite an already existing key) GenerateKey() error client.AuthDataMessenger }
func NewAuthManager ¶
func NewAuthManager(conf AuthManagerConfig) AuthManager
type AuthManagerConfig ¶
type Controller ¶
type Controller interface { IsAuthorized() bool Authorize() menderError GetCurrentArtifactName() (string, error) GetUpdatePollInterval() time.Duration GetInventoryPollInterval() time.Duration GetRetryPollInterval() time.Duration CheckUpdate() (*datastore.UpdateInfo, menderError) FetchUpdate(url string) (io.ReadCloser, int64, error) NewStatusReportWrapper(updateId string, stateId datastore.MenderState) *client.StatusReportWrapper ReportUpdateStatus(update *datastore.UpdateInfo, status string) menderError UploadLog(update *datastore.UpdateInfo, logs []byte) menderError InventoryRefresh() error CheckScriptsCompatibility() error GetScriptExecutor() statescript.Executor ReadArtifactHeaders(from io.ReadCloser) (*installer.Installer, error) GetInstallers() []installer.PayloadUpdatePerformer RestoreInstallersFromTypeList(payloadTypes []string) error StateRunner }
type DeploymentHook ¶
type DeploymentHook struct {
// contains filtered or unexported fields
}
func NewDeploymentLogHook ¶
func NewDeploymentLogHook(logManager *DeploymentLogManager) *DeploymentHook
func (DeploymentHook) Levels ¶
func (dh DeploymentHook) Levels() []logrus.Level
type DeploymentJSONFormatter ¶
type DeploymentJSONFormatter struct { // TimestampFormat sets the format used for marshaling timestamps. TimestampFormat string }
type DeploymentLogManager ¶
type DeploymentLogManager struct {
// contains filtered or unexported fields
}
var DeploymentLogger *DeploymentLogManager
Global deploymentlogger
func NewDeploymentLogManager ¶
func NewDeploymentLogManager(logDirLocation string) *DeploymentLogManager
func (*DeploymentLogManager) Disable ¶
func (dlm *DeploymentLogManager) Disable() error
func (*DeploymentLogManager) Enable ¶
func (dlm *DeploymentLogManager) Enable(deploymentID string) error
func (DeploymentLogManager) GetLogs ¶
func (dlm DeploymentLogManager) GetLogs(deploymentID string) ([]byte, error)
GetLogs is returns logs as a JSON []byte string. Function is having the same signature as json.Marshal() ([]byte, error)
func (DeploymentLogManager) Rotate ¶
func (dlm DeploymentLogManager) Rotate()
func (DeploymentLogManager) WriteLog ¶
func (dlm DeploymentLogManager) WriteLog(log []byte) error
type FileLogger ¶
type FileLogger struct {
// contains filtered or unexported fields
}
func NewFileLogger ¶
func NewFileLogger(name string) *FileLogger
NewFileLogger creates instance of file logger; it is initialized just before logging is started
func (*FileLogger) Deinit ¶
func (fl *FileLogger) Deinit() error
type Mender ¶
type Mender struct { *dev.DeviceManager // contains filtered or unexported fields }
func NewMender ¶
func NewMender(config *conf.MenderConfig, pieces MenderPieces) (*Mender, error)
func (*Mender) CheckScriptsCompatibility ¶
func (*Mender) CheckUpdate ¶
func (m *Mender) CheckUpdate() (*datastore.UpdateInfo, menderError)
Check if new update is available. In case of errors, returns nil and error that occurred. If no update is available *UpdateInfo is nil, otherwise it contains update information.
func (*Mender) FetchUpdate ¶
func (*Mender) ForceBootstrap ¶
func (m *Mender) ForceBootstrap()
func (*Mender) GetCurrentState ¶
func (*Mender) GetInventoryPollInterval ¶
func (*Mender) GetRetryPollInterval ¶
func (*Mender) GetScriptExecutor ¶
func (m *Mender) GetScriptExecutor() statescript.Executor
func (*Mender) GetUpdatePollInterval ¶
func (*Mender) InventoryRefresh ¶
func (*Mender) IsAuthorized ¶
func (*Mender) NewStatusReportWrapper ¶
func (m *Mender) NewStatusReportWrapper(updateId string, stateId datastore.MenderState) *client.StatusReportWrapper
func (*Mender) ReportUpdateStatus ¶
func (m *Mender) ReportUpdateStatus(update *datastore.UpdateInfo, status string) menderError
func (*Mender) SetNextState ¶
func (*Mender) TransitionState ¶
func (m *Mender) TransitionState(to State, ctx *StateContext) (State, bool)
type MenderAuthManager ¶
type MenderAuthManager struct {
// contains filtered or unexported fields
}
func (*MenderAuthManager) AuthToken ¶
func (m *MenderAuthManager) AuthToken() (client.AuthToken, error)
func (*MenderAuthManager) GenerateKey ¶
func (m *MenderAuthManager) GenerateKey() error
func (*MenderAuthManager) HasKey ¶
func (m *MenderAuthManager) HasKey() bool
func (*MenderAuthManager) IsAuthorized ¶
func (m *MenderAuthManager) IsAuthorized() bool
func (*MenderAuthManager) MakeAuthRequest ¶
func (m *MenderAuthManager) MakeAuthRequest() (*client.AuthRequest, error)
func (*MenderAuthManager) RecvAuthResponse ¶
func (m *MenderAuthManager) RecvAuthResponse(data []byte) error
func (*MenderAuthManager) RemoveAuthToken ¶
func (m *MenderAuthManager) RemoveAuthToken() error
type MenderDaemon ¶
type MenderDaemon struct { Mender Controller Sctx StateContext Store store.Store ForceToState chan State // contains filtered or unexported fields }
func NewDaemon ¶
func NewDaemon(mender Controller, store store.Store) *MenderDaemon
func (*MenderDaemon) Cleanup ¶
func (d *MenderDaemon) Cleanup()
func (*MenderDaemon) Run ¶
func (d *MenderDaemon) Run() error
func (*MenderDaemon) StopDaemon ¶
func (d *MenderDaemon) StopDaemon()
type MenderError ¶
type MenderError struct {
// contains filtered or unexported fields
}
func (*MenderError) Cause ¶
func (m *MenderError) Cause() error
func (*MenderError) Error ¶
func (m *MenderError) Error() string
func (*MenderError) IsFatal ¶
func (m *MenderError) IsFatal() bool
type MenderPieces ¶
type MenderPieces struct { DualRootfsDevice installer.DualRootfsDevice Store store.Store AuthMgr AuthManager }
type State ¶
type State interface { // Perform state action, returns next state and boolean flag indicating if // execution was cancelled or not Handle(ctx *StateContext, c Controller) (State, bool) HandleError(ctx *StateContext, c Controller, err menderError) (State, bool) // Cancel state action, returns true if action was cancelled Cancel() bool // Return numeric state ID Id() datastore.MenderState // Return transition Transition() Transition SetTransition(t Transition) }
func NewAuthorizeWaitState ¶
func NewAuthorizeWaitState() State
func NewCheckWaitState ¶
func NewCheckWaitState() State
func NewErrorState ¶
func NewErrorState(err menderError) State
func NewFetchStoreRetryState ¶
func NewFetchStoreRetryState(from State, update *datastore.UpdateInfo, err error) State
func NewReportErrorState ¶
func NewReportErrorState(update *datastore.UpdateInfo, status string) State
func NewUpdateAfterCommitState ¶
func NewUpdateAfterCommitState(update *datastore.UpdateInfo) State
func NewUpdateAfterFirstCommitState ¶
func NewUpdateAfterFirstCommitState(update *datastore.UpdateInfo) State
func NewUpdateAfterRebootState ¶
func NewUpdateAfterRebootState(update *datastore.UpdateInfo) State
func NewUpdateAfterRollbackRebootState ¶
func NewUpdateAfterRollbackRebootState(update *datastore.UpdateInfo) State
func NewUpdateAfterStoreState ¶
func NewUpdateAfterStoreState(update *datastore.UpdateInfo) State
func NewUpdateCleanupState ¶
func NewUpdateCleanupState(update *datastore.UpdateInfo, status string) State
func NewUpdateCommitState ¶
func NewUpdateCommitState(update *datastore.UpdateInfo) State
func NewUpdateErrorState ¶
func NewUpdateErrorState(err menderError, update *datastore.UpdateInfo) State
func NewUpdateFetchState ¶
func NewUpdateFetchState(update *datastore.UpdateInfo) State
func NewUpdateInstallState ¶
func NewUpdateInstallState(update *datastore.UpdateInfo) State
func NewUpdateRebootState ¶
func NewUpdateRebootState(update *datastore.UpdateInfo) State
func NewUpdateRollbackRebootState ¶
func NewUpdateRollbackRebootState(update *datastore.UpdateInfo) State
func NewUpdateRollbackState ¶
func NewUpdateRollbackState(update *datastore.UpdateInfo) State
func NewUpdateStatusReportState ¶
func NewUpdateStatusReportState(update *datastore.UpdateInfo, status string) State
func NewUpdateStoreState ¶
func NewUpdateStoreState(in io.ReadCloser, update *datastore.UpdateInfo) State
func NewUpdateVerifyRebootState ¶
func NewUpdateVerifyRebootState(update *datastore.UpdateInfo) State
func NewUpdateVerifyRollbackRebootState ¶
func NewUpdateVerifyRollbackRebootState(update *datastore.UpdateInfo) State
type StateCollection ¶
type StateCollection struct { Authorize *authorizeState AuthorizeWait *authorizeWaitState CheckWait *checkWaitState Final *finalState Idle *idleState Init *initState InventoryUpdate *inventoryUpdateState UpdateCheck *updateCheckState }
type StateContext ¶
type StateContext struct { // data store access Rebooter installer.Rebooter Store store.Store WakeupChan chan bool // contains filtered or unexported fields }
StateContext carrying over data that may be used by all state handlers
type StateRunner ¶
type Transition ¶
type Transition int
const ( // no transition is happening ToNone Transition = iota // initial transition ToIdle ToSync ToError ToDownload_Enter ToDownload_Leave ToArtifactInstall // should have Enter and Error actions ToArtifactReboot_Enter // should have Leave action only ToArtifactReboot_Leave ToArtifactCommit_Enter ToArtifactCommit_Leave ToArtifactRollback // should have Enter and Error actions ToArtifactRollbackReboot_Enter // should have Leave action only ToArtifactRollbackReboot_Leave ToArtifactFailure )
Transition in and out of state script states. Note in particular that update module specific states are not included here.
func (Transition) Enter ¶
func (t Transition) Enter(exec statescript.Executor, report *client.StatusReportWrapper, store store.Store) error
Transition implements statescript.Launcher interface
func (Transition) Error ¶
func (t Transition) Error(exec statescript.Executor, report *client.StatusReportWrapper) error
func (Transition) IsToError ¶
func (t Transition) IsToError() bool
func (Transition) Leave ¶
func (t Transition) Leave(exec statescript.Executor, report *client.StatusReportWrapper, store store.Store) error
func (Transition) String ¶
func (t Transition) String() string
type UpdateState ¶
type UpdateState interface { State Update() *datastore.UpdateInfo }