keeper

package
v0.0.0-...-df7806a Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BuildVersion     = "No Version Info"
	BuildGoVersion   = "No Version Info"
	BuildGitCommitId = "No Commit Info"
	BuildTime        = "No Time Info"
	Authors          = "No Authors Info"

)

Version相关信息

View Source
var DefaultKeeper = NewKeeper(fmt.Sprintf("Keeper_%s", gfile.Basename(os.Args[0])))

默认Keeper

Functions

func CloseCtrl

func CloseCtrl()

CloseCtrl 关闭ctrl管理功能

func SetName

func SetName(name string)

SetName 设置Keeper名 建议设置独特个性化的引用名,因为管理链接,日志目录等地方会用到它。 如果不设置,默认为"Keeper_xxx",启动xxx为二进制的名称

func Setup

func Setup(startFunction StartFunc)

Setup 设置并启动DefaultKeeper

func Shutdown

func Shutdown()

Shutdown 关闭服务

Types

type Keeper

type Keeper struct {
	*cobra.Command                    // 命令行参数解析
	*process.Manager                  // 进程管理者:保存所有Executor, Executor实现process.IProc接口
	ExecutorsRunning *gmap.StrAnyMap  // 主进程中,记录正在运行的Executors列表
	CurrentExecutor  string           // 子进程中,记录正在执行的Executor
	KeeperName       string           // 微服务管理者keeper的名称
	KeeperIsMaster   bool             // 是否为主进程
	KConfigPath      string           // 配置文件路径
	KConfig          *gcfg.Config     // keeper的配置信息
	AppsToOperate    *garray.StrArray // 记录当前需要启动或停止的App的名称列表
	PidFilePath      string           // 主进程的pid文件保存路径
	ProcMode         ktype.ProcMode   // 进程模式,MultiProcs:多进程模式;SingleProc:单进程模式, 默认单进程
	StartFunction    StartFunc        // keeper启动方法
	StartTime        *gtime.Time      // keeper启动时间
	Exiting          bool             // keeper正在关闭
	BeforeStopFunc   StopFunc         // 服务关闭之前执行该方法
	CanCtrl          bool             // 是否开启交互式shell功能,默认true
	KCtrl            *goktrl.Ktrl     // 交互式shell
	KCtrlSocket      string           // 默认Unix套接字名称
	IsCtrlInitiated  bool             // KCtrl是否已经初始化

}
  Keeper 微服务管理者,主要是进程管理;
  主要功能有:
    进程开启、停止、重启——process.Manager;
	交互式shell命令——KCtrl;
	平滑重启——Kgrace;
	命令行参数解析——cobra.Command;

func NewKeeper

func NewKeeper(name string) *Keeper

NewKeeper Keeper工厂函数

func (*Keeper) AddAppToExecutor

func (that *Keeper) AddAppToExecutor(app kapp.IApp, executorName ...string)

AddAppToExecutor 向Executor中添加App;executorName执行器名称作为可选参数; 如果传入了executorName,则使用相应的Executor; 如果未传入executorName,则使用与Keeper同名的默认Executor; 如果要使用的Executor不存在,则先创建; 本方法主要是在用户编写的startFunction中调用,以便将用户编写的App加入到对应的Executor中;

func (*Keeper) CheckKeeperForStart

func (that *Keeper) CheckKeeperForStart()

CheckKeeperStart 检查keeper是否已经启动过; 如果主进程的pid文件名存在,则说明keeper已经启动过。

func (*Keeper) Config

func (that *Keeper) Config() *gcfg.Config

以下方法实现Executor需要的IKeeper接口

func (*Keeper) EnableMultiProc

func (that *Keeper) EnableMultiProc()

是否开启多进程模式,也是由用户在startFunction中调用,开启多进程模式

func (*Keeper) GetExecutorsRunning

func (that *Keeper) GetExecutorsRunning() *gmap.StrAnyMap

func (*Keeper) GetGFConf

func (that *Keeper) GetGFConf(confFile string) *gcfg.Config

传入配置文件地址,获取gcfg对象

func (*Keeper) InitCli

func (that *Keeper) InitCli()

命令行初始化

func (*Keeper) InitKtrl

func (that *Keeper) InitKtrl()

func (*Keeper) InitLogCfg

func (that *Keeper) InitLogCfg()

将配置文件中的配置信息写入到logger配置中

func (*Keeper) InitLogSetting

func (that *Keeper) InitLogSetting(config *gcfg.Config) error

日志初始化 通过参数设置日志级别 日志级别通过环境默认分三个类型,开发环境,测试环境,生产环境 开发环境: 日志级别为 DEVELOP,标准输出打开 测试环境:日志级别为 INFO,除了debug日志,都会被打印,标准输出关闭 生产环境: 日志级别为 PRODUCT,会打印 WARN,ERRO,CRIT三个级别的日志,标准输出为关闭 Debug开关会无视以上设置,强制把日志级别设置为ALL,并且打开标准输出。

func (*Keeper) IsMaster

func (that *Keeper) IsMaster() bool

func (*Keeper) IsMutilProcModeAndInMaster

func (that *Keeper) IsMutilProcModeAndInMaster() bool

IsMutilProcModeAndInMaster 判断是否是多进程模式,并且当前正在主进程中执行

func (*Keeper) IsSingleProcMode

func (that *Keeper) IsSingleProcMode() bool

func (*Keeper) KCtrlCheckExecutor

func (that *Keeper) KCtrlCheckExecutor(c *goktrl.Context) bool

func (*Keeper) KtrlDebug

func (that *Keeper) KtrlDebug()

func (*Keeper) KtrlLog

func (that *Keeper) KtrlLog()

func (*Keeper) KtrlReload

func (that *Keeper) KtrlReload()

func (*Keeper) KtrlStartApps

func (that *Keeper) KtrlStartApps()

KtrlStartApp 启动App

func (*Keeper) KtrlStartExecutor

func (that *Keeper) KtrlStartExecutor()

KtrlStartExecutor 启动一个Executor,可以指定启动一部分app

func (*Keeper) KtrlStopApps

func (that *Keeper) KtrlStopApps()

func (*Keeper) KtrlStopExecutor

func (that *Keeper) KtrlStopExecutor()

KtrlStopExecutor 停止一个Executor

func (*Keeper) ListOfAppsToStart

func (that *Keeper) ListOfAppsToStart() *garray.StrArray

func (*Keeper) Mode

func (that *Keeper) Mode() ktype.ProcMode

func (*Keeper) ParseConfig

func (that *Keeper) ParseConfig(conf string)

命令行参数解析和设置

func (*Keeper) ParseDaemon

func (that *Keeper) ParseDaemon(daemon bool)

func (*Keeper) ParseDebug

func (that *Keeper) ParseDebug(debug bool)

func (*Keeper) ParseEnv

func (that *Keeper) ParseEnv(env string)

func (*Keeper) ParsePidFilePath

func (that *Keeper) ParsePidFilePath(pidFilePath string)

func (*Keeper) ProcManager

func (that *Keeper) ProcManager() *process.Manager

func (*Keeper) PutMasterPidInFile

func (that *Keeper) PutMasterPidInFile()

将主进程的pid写入pid文件

func (*Keeper) RunExecutors

func (that *Keeper) RunExecutors()

RunExecutors 根据命令行参数执行ExecutorList中的Executor

func (*Keeper) RunKeeper

func (that *Keeper) RunKeeper()

RunKeeper keeper的start命令的执行入口

func (*Keeper) SetAppsToOperate

func (that *Keeper) SetAppsToOperate(appNames []string)

func (*Keeper) SetCurrentExecutor

func (that *Keeper) SetCurrentExecutor(execName string)

func (*Keeper) SetRootCommand

func (that *Keeper) SetRootCommand(c *cobra.Command)

func (*Keeper) SetupStartFunc

func (that *Keeper) SetupStartFunc(startFunction StartFunc)

SetupStartFunc 启动服务,并执行传入的启动方法; 本方法是用户执行的起始入口; 参数startFunction: 启动时需要执行的方法;

func (*Keeper) Shutdown

func (that *Keeper) Shutdown(timeout ...time.Duration)

Shutdown 主动结束进程

func (*Keeper) StartApps

func (that *Keeper) StartApps(execName string, appNames ...string) (r string)

StartApps 交互式shell启动Apps,只在子进程中或者单进程模式下执行

func (*Keeper) StartExecutor

func (that *Keeper) StartExecutor(execName string, appNames ...string) (r string)

StartExecutor 交互式shell开启Executor,只在主进程中执行

func (*Keeper) StopApps

func (that *Keeper) StopApps(appName string) (r string)

func (*Keeper) StopExecutor

func (that *Keeper) StopExecutor(execName string) (r string)

func (*Keeper) StopKeeper

func (that *Keeper) StopKeeper(sig string)

StopKeeper keeper的stop、reload、quit命令的执行入口

func (*Keeper) Version

func (that *Keeper) Version()

Version 显示版本信息

type StartFunc

type StartFunc func(k *Keeper)

StartFunc keeper启动时的回调方法

type StopFunc

type StopFunc func(k *Keeper) bool

StopFunc keeper关闭前的回调方法

Jump to

Keyboard shortcuts

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