Feat: Add some parameters (#294)
This commit is contained in:
parent
f545a441e0
commit
150612a1d9
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/naiba/nezha/cmd/dashboard/controller"
|
"github.com/naiba/nezha/cmd/dashboard/controller"
|
||||||
@ -9,13 +10,30 @@ import (
|
|||||||
"github.com/naiba/nezha/model"
|
"github.com/naiba/nezha/model"
|
||||||
"github.com/naiba/nezha/service/singleton"
|
"github.com/naiba/nezha/service/singleton"
|
||||||
"github.com/ory/graceful"
|
"github.com/ory/graceful"
|
||||||
|
flag "github.com/spf13/pflag"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DashboardCliParam struct {
|
||||||
|
Version bool // 当前版本号
|
||||||
|
ConfigFile string // 配置文件路径
|
||||||
|
DatebaseLocation string // Sqlite3 数据库文件路径
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
dashboardCliParam DashboardCliParam
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
flag.CommandLine.ParseErrorsWhitelist.UnknownFlags = true
|
||||||
|
flag.BoolVarP(&dashboardCliParam.Version, "version", "v", false, "查看当前版本号")
|
||||||
|
flag.StringVarP(&dashboardCliParam.ConfigFile, "config", "c", "data/config.yaml", "配置文件路径")
|
||||||
|
flag.StringVar(&dashboardCliParam.DatebaseLocation, "db", "data/sqlite.db", "Sqlite3数据库文件路径")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
// 初始化 dao 包
|
// 初始化 dao 包
|
||||||
singleton.InitConfigFromPath("data/config.yaml")
|
singleton.InitConfigFromPath(dashboardCliParam.ConfigFile)
|
||||||
singleton.InitTimezoneAndCache()
|
singleton.InitTimezoneAndCache()
|
||||||
singleton.InitDBFromPath("data/sqlite.db")
|
singleton.InitDBFromPath(dashboardCliParam.DatebaseLocation)
|
||||||
singleton.InitLocalizer()
|
singleton.InitLocalizer()
|
||||||
initSystem()
|
initSystem()
|
||||||
}
|
}
|
||||||
@ -36,6 +54,11 @@ func initSystem() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if dashboardCliParam.Version {
|
||||||
|
fmt.Println(singleton.Version)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
singleton.CleanMonitorHistory()
|
singleton.CleanMonitorHistory()
|
||||||
go rpc.ServeRPC(singleton.Conf.GRPCPort)
|
go rpc.ServeRPC(singleton.Conf.GRPCPort)
|
||||||
serviceSentinelDispatchBus := make(chan model.Monitor) // 用于传递服务监控任务信息的channel
|
serviceSentinelDispatchBus := make(chan model.Monitor) // 用于传递服务监控任务信息的channel
|
||||||
@ -44,7 +67,7 @@ func main() {
|
|||||||
go singleton.AlertSentinelStart()
|
go singleton.AlertSentinelStart()
|
||||||
singleton.NewServiceSentinel(serviceSentinelDispatchBus)
|
singleton.NewServiceSentinel(serviceSentinelDispatchBus)
|
||||||
srv := controller.ServeWeb(singleton.Conf.HTTPPort)
|
srv := controller.ServeWeb(singleton.Conf.HTTPPort)
|
||||||
graceful.Graceful(func() error {
|
if err := graceful.Graceful(func() error {
|
||||||
return srv.ListenAndServe()
|
return srv.ListenAndServe()
|
||||||
}, func(c context.Context) error {
|
}, func(c context.Context) error {
|
||||||
log.Println("NEZHA>> Graceful::START")
|
log.Println("NEZHA>> Graceful::START")
|
||||||
@ -52,5 +75,7 @@ func main() {
|
|||||||
log.Println("NEZHA>> Graceful::END")
|
log.Println("NEZHA>> Graceful::END")
|
||||||
srv.Shutdown(c)
|
srv.Shutdown(c)
|
||||||
return nil
|
return nil
|
||||||
})
|
}); err != nil {
|
||||||
|
log.Printf("NEZHA>> ERROR: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user