cmd

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: LGPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InitFuncNoDeferListForIotCore = []NoDeferFunc{
	{model.InitCoreLogic, "核心处理逻辑"},
	{service.TSLTable().CreateDatabase, "时序数据库创建"},
	{service.TdLogTable().CreateStable, "时序库日志表创建"},
	{service.DevInit().InitProductForTd, "时序库产品表初始化"},
	{service.DevInit().InitDeviceForTd, "时序库设备表初始化"},
	{service.DevDevice().CacheDeviceDetailList, "缓存设备信息"},
	{service.AlarmRule().CacheAllAlarmRule, "缓存告警规则"},
	{network.ReloadNetwork, "网络服务"},
}
View Source
var InitFuncNoDeferListWebAdmin = []NoDeferFunc{
	{service.SysAuthorize().InitAuthorize, "系统权限"},
	{initSystemStatistics, "系统统计"},
	{service.SysInfo().ServerInfoEscalation, "集群数据"},
	{initPlugins, "插件"},
}
View Source
var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start sagoo-iot server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			var signalChannel = make(chan os.Signal, 1)

			enablePProf := g.Cfg().MustGet(context.Background(), "system.enablePProf").Bool()
			if enablePProf {
				pprofPort := g.Cfg().MustGet(context.Background(), "system.pprofPort").String()
				if pprofPort == "" {
					pprofPort = "58089"
				}
				RunSystemAnalysis(signalChannel, pprofPort)
			}

			deferFuncListIotCore, err := InitSystemDeferFunc(ctx)
			defer func() {
				for _, f := range deferFuncListIotCore {
					if f == nil {
						continue
					}
					if deferErr := f(ctx); deferErr != nil {
						fmt.Printf("defer func error: %s\n", deferErr.Error())
					}
				}
			}()

			err = InitSystem(ctx, InitFuncNoDeferListForIotCore)
			if err != nil {
				fmt.Printf("defer func error: %s\n", err.Error())
			}

			err = InitSystem(ctx, InitFuncNoDeferListWebAdmin)
			if err != nil {
				fmt.Printf("defer func error: %s\n", err.Error())
			}

			sse.Init()
			RunServer(ctx, signalChannel)
			signal.Notify(signalChannel, os.Interrupt, os.Kill, syscall.SIGTERM)
			fmt.Println("收到关闭服务信号:", <-signalChannel)
			time.Sleep(time.Second * 3)
			tdengine.Close()
			fmt.Println("成功关闭服务器")
			return
		},
	}
)

Functions

func AllSystemInit

func AllSystemInit(ctx context.Context)

func InitSystem

func InitSystem(ctx context.Context, noDeferFuncList []NoDeferFunc) error

func InitSystemDeferFunc

func InitSystemDeferFunc(ctx context.Context) ([]func(context.Context) error, error)

func InitTrace

func InitTrace(ctx context.Context)

InitTrace 初始化链路追踪

func RunQueue

func RunQueue(ctx context.Context) (error, func(context.Context) error)

func RunServer

func RunServer(ctx context.Context, stopSignal chan os.Signal)

func RunSystemAnalysis

func RunSystemAnalysis(stopSignal chan os.Signal, pprofPort string)

func SetGFMode

func SetGFMode(ctx context.Context)

SetGFMode 设置gf运行模式

Types

type DeferFunc

type DeferFunc struct {
	F    func(ctx context.Context) (error, func(context.Context) error)
	Desc string
}

type NoDeferFunc

type NoDeferFunc struct {
	F    func(ctx context.Context) error
	Desc string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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