upgrader

package module
v0.0.0-...-172ad5f Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: AGPL-3.0 Imports: 19 Imported by: 0

README

upgrader

介绍

Smooth upgrader

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SIGUSR1 = syscall.SIGUSR1
	SIGUSR2 = syscall.SIGUSR2
	SIGTERM = syscall.SIGTERM
)
View Source
var (
	//DisabledState is a placeholder state for when
	//upgrader is disabled and the program function
	//is run manually.
	DisabledState = State{Enabled: false}
)

Functions

func IsSupported

func IsSupported() bool

IsSupported returns whether upgrader is supported on the current OS.

func Restart

func Restart()

Restart programmatically triggers a graceful restart. If NoRestart is enabled, then this will essentially be a graceful shutdown.

func Run

func Run(c Config)

Run executes upgrader, if an error is encountered, upgrader fallsback to running the program directly (unless Required is set).

func RunErr

func RunErr(c Config) error

RunErr allows manual handling of any upgrader errors.

func SanityCheck

func SanityCheck()

SanityCheck manually runs the check to ensure this binary is compatible with upgrader. This tries to ensure that a restart is never performed against a bad binary, as it would require manual intervention to rectify. This is automatically done on upgrader.Run() though it can be manually run prior whenever necessary.

Types

type Config

type Config struct {
	Required bool              // 防止upgrade在主进程失败时回退到运行
	Program  func(state State) // 执行被控程序的主程序
	//Program's zero-downtime socket listening address (set this or Addresses)
	Address string
	//Program's zero-downtime socket listening addresses (set this or Address)
	Addresses []string
	//RestartSignal will manually trigger a graceful restart. Defaults to SIGUSR2.
	RestartSignal os.Signal
	//TerminateTimeout controls how long upgrader should
	//wait for the program to terminate itself. After this
	//timeout, upgrader will issue a SIGKILL.
	TerminateTimeout time.Duration
	//MinFetchInterval defines the smallest duration between Fetch()s.
	//This helps to prevent unwieldy fetch.Interfaces from hogging
	//too many resources. Defaults to 1 second.
	MinFetchInterval time.Duration
	//PreUpgrade runs after a binary has been retrieved, user defined checks
	//can be run here and returning an error will cancel the upgrade.
	PreUpgrade func(tempBinaryPath string) error
	//Debug enables all [upgrader] logs.
	Debug bool
	//NoWarn disables warning [upgrader] logs.
	NoWarn bool
	//NoRestart disables all restarts, this option essentially converts
	//the RestartSignal into a "ShutdownSignal".
	NoRestart bool
	//NoRestartAfterFetch disables automatic restarts after each upgrade.
	//Though manual restarts using the RestartSignal can still be performed.
	NoRestartAfterFetch bool
	//Fetcher will be used to fetch binaries.
	Fetcher fetcher.Fetcher
}

Config defines upgrader's run-time configuration

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

notifying on close net.Conn

func (Conn) Close

func (o Conn) Close() error

type Listener

type Listener struct {
	net.Listener
	// contains filtered or unexported fields
}

gracefully closing net.Listener

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

func (*Listener) Close

func (l *Listener) Close() error

blocking wait for close

func (*Listener) File

func (l *Listener) File() *os.File

type State

type State struct {
	//whether upgrader is running enabled. When enabled,
	//this program will be running in a child process and
	//upgrader will perform rolling upgrades.
	Enabled bool
	//ID is a SHA-1 hash of the current running binary
	ID string
	//StartedAt records the start time of the program
	StartedAt time.Time
	//Listener is the first net.Listener in Listeners
	Listener net.Listener
	//Listeners are the set of acquired sockets by the master
	//process. These are all passed into this program in the
	//same order they are specified in Config.Addresses.
	Listeners []net.Listener
	//Program's first listening address
	Address string
	//Program's listening addresses
	Addresses []string
	//GracefulShutdown will be filled when its time to perform
	//a graceful shutdown.
	GracefulShutdown chan bool
	//Path of the binary currently being executed
	BinPath string
}

State contains the current run-time state of upgrader

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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