Documentation ¶
Overview ¶
Package restart implements requesting restarts from any part of the code that has access to state. It also implements a mimimal manager to take care of restart state.
Index ¶
- func ClearReboot(st *state.State)
- func FinishTaskWithRestart(t *state.Task, status state.Status, restartType RestartType, snapName string, ...) error
- func MarkTaskAsRestartBoundary(t *state.Task, dir RestartBoundaryDirection)
- func MockAfterRestartForChange(chg *state.Change)
- func PendingForChange(st *state.State, chg *state.Change) bool
- func PendingForChangeTasks(st *state.State, chg *state.Change, considerTasks map[string]bool) bool
- func ReplaceBootID(st *state.State, bootID string)
- func Request(st *state.State, t RestartType, rebootInfo *boot.RebootInfo)
- func TaskIsRestartBoundary(t *state.Task, dir RestartBoundaryDirection) bool
- func TaskWaitForRestart(t *state.Task) error
- type Handler
- type RestartBoundaryDirection
- type RestartManager
- type RestartParameters
- type RestartType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearReboot ¶
ClearReboot clears state information about tracking requested reboots.
func FinishTaskWithRestart ¶
func FinishTaskWithRestart(t *state.Task, status state.Status, restartType RestartType, snapName string, rebootInfo *boot.RebootInfo) error
FinishTaskWithRestart either schedules a restart for the given task or it does an immediate restart of the snapd daemon, depending on the type of restart provided. For SystemRestart and friends, the restart is scheduled and postponed until the change has run out of tasks to run. For tasks that request restarts as a part of their undo, any tasks that previously scheduled restarts as a part of their 'do' will be unscheduled.
func MarkTaskAsRestartBoundary ¶
func MarkTaskAsRestartBoundary(t *state.Task, dir RestartBoundaryDirection)
MarkTaskAsRestartBoundary sets a task as a restart boundary. That means the change cannot continue beyond this task, before a restart has taken place. 'path' indicates which execution direction(s) it will be a restart boundary for.
func MockAfterRestartForChange ¶
MockAfterRestartForChange is added solely for unit test purposes, to help simulate restarts.
func PendingForChange ¶
PendingForChange checks if a system restart is pending for a change.
func PendingForChangeTasks ¶
PendingForChangeTasks checks if a system restart is pending for a change, ignoring tasks other than the task IDs supplied.
func ReplaceBootID ¶
func Request ¶
func Request(st *state.State, t RestartType, rebootInfo *boot.RebootInfo)
Request asks for a restart of the managing process. The state needs to be locked to request a restart.
func TaskIsRestartBoundary ¶
func TaskIsRestartBoundary(t *state.Task, dir RestartBoundaryDirection) bool
TaskIsRestartBoundary returns true if the task is a restart-boundary for the given direction.
func TaskWaitForRestart ¶
TaskWaitForRestart can be used for tasks that need to wait for a pending restart to occur, meant to be used in conjunction with PendingForChange. The task will then be re-run after the restart has occurred. This is only supported for tasks that are currently in Doing/Undoing and is only safe to call from the task itself. After calling this, the task should immediately return.
Types ¶
type Handler ¶
type Handler interface { HandleRestart(t RestartType, rebootInfo *boot.RebootInfo) // RebootAsExpected is called early when either a reboot was // requested by snapd and happened or no reboot was expected at all. RebootAsExpected(st *state.State) error // RebootDidNotHappen is called early instead when a reboot was // requested by snapd but did not happen. RebootDidNotHappen(st *state.State) error }
Handler can handle restart requests and whether expected reboots happen.
type RestartBoundaryDirection ¶
type RestartBoundaryDirection int
RestartBoundaryDirection defines in which direction a task may have a restart boundary set. A restart boundary is when the task must restart, before it's dependencies can continue. A restart boundary may be either in the 'Do' direction, or the 'Undo' direction.
const ( // RestartBoundaryDirectionDo is a restart boundary in the 'Do' direction RestartBoundaryDirectionDo RestartBoundaryDirection = 1 << iota // RestartBoundaryDirectionUndo is a restart boundary in the 'Undo' direction RestartBoundaryDirectionUndo RestartBoundaryDirection = 1 << iota )
func (RestartBoundaryDirection) MarshalJSON ¶
func (rb RestartBoundaryDirection) MarshalJSON() ([]byte, error)
func (*RestartBoundaryDirection) String ¶
func (rb *RestartBoundaryDirection) String() string
func (*RestartBoundaryDirection) UnmarshalJSON ¶
func (rb *RestartBoundaryDirection) UnmarshalJSON(data []byte) error
type RestartManager ¶
type RestartManager struct {
// contains filtered or unexported fields
}
RestartManager takes care of restart-related state.
func Manager ¶
Manager returns a new restart manager and initializes the support for restarts requests. It takes the current boot id to track and verify reboots and a Handler that handles the actual requests and reacts to reboot happening. It must be called with the state lock held.
func (*RestartManager) Ensure ¶
func (m *RestartManager) Ensure() error
Ensure implements StateManager.Ensure. Required by StateEngine, we actually do nothing here.
func (*RestartManager) StartUp ¶
func (m *RestartManager) StartUp() error
StartUp implements StateStarterUp.Startup.
func (*RestartManager) Stop ¶
func (rm *RestartManager) Stop()
Stop implements StateStopper. It will unregister the change callback handler from state.
type RestartParameters ¶
type RestartParameters struct { SnapName string `json:"snap-name,omitempty"` RestartType RestartType `json:"restart-type,omitempty"` BootloaderOptions *bootloader.Options `json:"bootloader-options,omitempty"` }
type RestartType ¶
type RestartType int
const ( RestartUnset RestartType = iota RestartDaemon RestartSystem // RestartSystemNow is like RestartSystem but action is immediate RestartSystemNow // RestartSocket will restart the daemon so that it goes into // socket activation mode. RestartSocket // Stop just stops the daemon (used with image pre-seeding) StopDaemon // RestartSystemHaltNow will shutdown --halt the system asap RestartSystemHaltNow // RestartSystemPoweroffNow will shutdown --poweroff the system asap RestartSystemPoweroffNow )
func MockPending ¶
func MockPending(st *state.State, restarting RestartType) RestartType