stagemanager

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsActiveUpgrading added in v1.0.0

func IsActiveUpgrading() bool

IsActiveUpgrading just for backward compatible means the current application is upgrading from an old application, and not running yet. may be inheriting connections or configuration from old one.

func NoticeStop

func NoticeStop(action StopAction)

NoticeStop notices the stop action to stage manager

func OnBeforeStopStage

func OnBeforeStopStage(f func(StopAction, Application) error)

will exit with non-zero code when a callback handler return error

func OnGracefulStop

func OnGracefulStop(f func() error)

will exit with non-zero code when a callback handler return error

func RegisterOnStateChanged

func RegisterOnStateChanged(f func(State))

func RegisterUpgradeHandler

func RegisterUpgradeHandler(f func() error)

func SetState

func SetState(s State)

expose this method just make UT easier, should not use it directly.

func StartNewServer

func StartNewServer() error

Types

type Application

type Application interface {
	// inherit config from old server when it exists, otherwise, use the local config
	// init its object members
	Init(*v2.MOSNConfig) error
	// start to work, accepting new connections
	Start()
	// transfer existing connection from old server for smooth upgrade
	InheritConnections() error
	// Shutdown means graceful stop
	Shutdown() error
	// Close means stop working immediately
	// It will skip stop reconfigure domain socket when is upgrading
	Close(isUpgrade bool)
	// IsFromUpgrade application start from upgrade mode,
	// means inherit connections and configuration(if enabled) from old application.
	IsFromUpgrade() bool
}

the current Application is Mosn, we may implement more applications in the future.

type Data

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

Data contains objects used in stages

type StageManager

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

StageManager is used to controls service life stages.

func InitStageManager

func InitStageManager(ctx *cli.Context, path string, app Application) *StageManager

func (*StageManager) AppendAfterStartStage

func (stm *StageManager) AppendAfterStartStage(f func(Application)) *StageManager

after start, already working (accepting request)

func (*StageManager) AppendAfterStopStage

func (stm *StageManager) AppendAfterStopStage(f func(Application)) *StageManager

after application is not working

func (*StageManager) AppendBeforeStopStage

func (stm *StageManager) AppendBeforeStopStage(f func(StopAction, Application) error) *StageManager

will exit with non-zero code when a callback handler return error

func (*StageManager) AppendGracefulStopStage

func (stm *StageManager) AppendGracefulStopStage(f func(Application) error) *StageManager

graceful stop handlers, will exit with non-zero code when a callback handler return error

func (*StageManager) AppendInitStage

func (stm *StageManager) AppendInitStage(f func(*v2.MOSNConfig)) *StageManager

init work base on the local config

func (*StageManager) AppendParamsParsedStage

func (stm *StageManager) AppendParamsParsedStage(f func(*cli.Context)) *StageManager

func (*StageManager) AppendPreStartStage

func (stm *StageManager) AppendPreStartStage(f func(Application)) *StageManager

more init works after inherit config from old server and new server inited

func (*StageManager) AppendStartStage

func (stm *StageManager) AppendStartStage(f func(Application)) *StageManager

start

func (*StageManager) Run

func (stm *StageManager) Run()

Run until the application is started

func (*StageManager) RunAll

func (stm *StageManager) RunAll()

run all stages

func (*StageManager) SetState

func (stm *StageManager) SetState(s State)

expose this method just make UT easier, should not use it directly.

func (*StageManager) Stop

func (stm *StageManager) Stop()

exit code: 0: normal exit, no error happens 1: failed to start 4: run before-stop/graceful-stop callback failed

func (*StageManager) StopMosnProcess added in v1.0.0

func (stm *StageManager) StopMosnProcess() (err error)

StopMosnProcess stops Mosn process via command line, and it not support stop on windows.

func (*StageManager) WaitFinish

func (stm *StageManager) WaitFinish()

used for the main goroutine wait the finish signal if Run is not called, return directly

type State

type State int
const (
	Nil State = iota
	ParamsParsed
	Initing
	PreStart
	Starting
	AfterStart
	Running
	BeforeStop
	GracefulStopping
	Stopping
	AfterStop
	Stopped

	StartingNewServer // start a new server when got HUP signal
	Upgrading         // old server smooth upgrade
)

There are 11 main stages: 1. The parameters parsed stage. In this stage, parse different parameters from cli.Context, and finally call config load to create a MOSNConfig.

  1. The initialize stage. In this stage, do some init actions based on config, and finally call Application.Init.
  2. The pre-startup stage. In this stage, creates some basic instance after executing Application.Init.
  3. The startup stage. In this stage, do some startup actions such as connections transfer for smooth upgrade and so on.
  4. The after-start stage. In this stage, do some other init actions after startup.
  5. The running stage.
  6. The before-stop stage. In this stage, do actions depend on the "stop action" before stopping service actually, like: unpub from registry or checking the unpub status, make sure it's safer for graceful stop.
  7. The graceful stop stage. In this stage, stop listen and graceful stop the existing connections.
  8. The stop stage. In this stage, executing Application.Close.
  9. The after-stop stage. In this stage, do some clean up actions after executing Application.Close
  10. The stopped stage. everything is closed.

The difference between pre-startup stage and startup stage is that startup stage has already accomplished the resources that used to startup application.

And, there are 2 additional stages:

  1. Starting a new server. It's for the old server only. The current server will fork a new server when it receives the HUP signal.
  2. Upgrading. It's for the old server only too. It means that the new server already started, and the old server is transferring the config and existing connections to the new server.

func GetState

func GetState() State

type StopAction

type StopAction int
const (
	Stop         StopAction = iota // stop directly
	GracefulStop                   // graceful stop the existing connections
	Reload                         // start a new server
	Upgrade                        // transfer the existing connections to new server
)

Jump to

Keyboard shortcuts

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