diff --git a/config/config.go b/config/config.go index a55a480..d5d7d66 100644 --- a/config/config.go +++ b/config/config.go @@ -526,8 +526,10 @@ func modifyConfigWhenRunInDocker() { } Config.GateWay.LanPort = 12841 Config.GateWay.TlsLanPort = 18569 - } else { + Config.EnvDefaultVal.SYSTEM_AGENT_URL_DEVICE_INFO = "http://localhost:5680/agent/v1/api/device/info" + Config.EnvDefaultVal.SYSTEM_AGENT_URL_BASE = "http://localhost:5680/agent/v1/api" + Config.Web.DockerLocalListenAddr = "localhost:5680" Config.GateWay.LanPort = 80 Config.GateWay.TlsLanPort = 443 } diff --git a/main.go b/main.go index 89e2903..1b82f70 100644 --- a/main.go +++ b/main.go @@ -19,105 +19,106 @@ * @LastEditTime: 2022-06-06 11:28:46 * @Description: */ - package main - - import ( - "agent/biz/alivechecker" - "agent/biz/disk_space_monitor/log_dir_monitor" - "agent/biz/docker" - "agent/config" - "strings" - - "agent/biz/model/clientinfo" - "agent/biz/model/device" - "agent/biz/model/did/leveldb" - "agent/biz/service/platform" - "agent/biz/service/upgrade" - "agent/biz/web" - "agent/utils/logger" - "fmt" - "os" - "os/signal" - "syscall" - - serviceswithplatform "agent/biz/service/switch-platform" - // _ "net/http/pprof" - ) - - func main() { - - logger.SetLogPath(config.Config.Log.Path) - logger.SetLogConfig(int(config.Config.Log.RotationSize), - int(config.Config.Log.RotationCount), - int(config.Config.Log.MaxAge), false) - logger.PrecreateAllLoggers() - - config.Version = Version - config.VersionNumber = VersionNumber - - logger.AppLogger().Infof("================[%v Started] [system-agent version:%v]================", - os.Args[0], config.Version+"-"+config.VersionNumber) - - fmt.Printf("AoLogDirBase:%+v\n", config.Config.Log.AoLogDirBase) - fmt.Printf("singleDockerModeEnv:%+v\n", os.Getenv(config.Config.Box.RunInDocker.AoSpaceSingleDockerModeEnv)) - - if err := AgentCmd.Execute(); err != nil { - fmt.Println(err) - os.Exit(1) - } - device.InitDeviceInfo() - device.InitDeviceKey() - clientinfo.InitClientInfo() - - if !strings.EqualFold(os.Getenv(config.Config.Box.RunInDocker.AoSpaceSingleDockerModeEnv), "true") { - go platform.InitPlatformAbility() - serviceswithplatform.RetryUnfinishedStatus() - upgrade.CronForUpgrade() - } - - // 启动 web/http api 服务 - web.Start() - - // 启动 docker 微服务创建或启动 - if !strings.EqualFold(os.Getenv(config.Config.Box.RunInDocker.AoSpaceSingleDockerModeEnv), "true") { - docker.Start() - } - alivechecker.Start() - - // 检测是否需要发送升级推送 - if !strings.EqualFold(os.Getenv(config.Config.Box.RunInDocker.AoSpaceSingleDockerModeEnv), "true") { - go upgrade.CheckUpgradeSucc() - } - - // 日志目录监控 - log_dir_monitor.Start() - - if err := leveldb.OpenDB(); err != nil { - fmt.Printf("\nFailed leveldb.OpenDB, err:%v\n", err) - os.Exit(0) - } - - quitChan := make(chan os.Signal) - signal.Notify(quitChan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, - syscall.SIGQUIT, syscall.SIGUSR1, syscall.SIGUSR2) - - for s := range quitChan { - switch s { - case syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT: - fmt.Printf("signal %v\n", s) - GracefullExit() - case syscall.SIGUSR1: - // fmt.Println("usr1 signal", s) - case syscall.SIGUSR2: - // fmt.Println("usr2 signal", s) - default: - // fmt.Println("other signal", s) - } - } - - } - - func GracefullExit() { - os.Exit(0) - } - \ No newline at end of file +package main + +import ( + "agent/biz/alivechecker" + "agent/biz/disk_space_monitor/log_dir_monitor" + "agent/biz/docker" + "agent/config" + "strings" + + "agent/biz/model/clientinfo" + "agent/biz/model/device" + "agent/biz/model/did/leveldb" + "agent/biz/service/platform" + "agent/biz/service/upgrade" + "agent/biz/web" + "agent/utils/logger" + "fmt" + "os" + "os/signal" + "syscall" + + serviceswithplatform "agent/biz/service/switch-platform" + // _ "net/http/pprof" +) + +func main() { + + logger.SetLogPath(config.Config.Log.Path) + logger.SetLogConfig(int(config.Config.Log.RotationSize), + int(config.Config.Log.RotationCount), + int(config.Config.Log.MaxAge), false) + logger.PrecreateAllLoggers() + + config.Version = Version + config.VersionNumber = VersionNumber + + logger.AppLogger().Infof("================[%v Started] [system-agent version:%v]================", + os.Args[0], config.Version+"-"+config.VersionNumber) + + fmt.Printf("AoLogDirBase:%+v\n", config.Config.Log.AoLogDirBase) + fmt.Printf("singleDockerModeEnv:%+v\n", os.Getenv(config.Config.Box.RunInDocker.AoSpaceSingleDockerModeEnv)) + + if err := AgentCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } + device.InitDeviceInfo() + device.InitDeviceKey() + clientinfo.InitClientInfo() + + if !strings.EqualFold(os.Getenv(config.Config.Box.RunInDocker.AoSpaceSingleDockerModeEnv), "true") { + go platform.InitPlatformAbility() + serviceswithplatform.RetryUnfinishedStatus() + upgrade.CronForUpgrade() + } + + // 启动 web/http api 服务 + web.Start() + + // 启动 docker 微服务创建或启动 + if strings.EqualFold(os.Getenv(config.Config.Box.RunInDocker.AoSpaceSingleDockerModeEnv), "true") { + docker.MigrateFileStorageData() + } else { + docker.Start() + } + alivechecker.Start() + + // 检测是否需要发送升级推送 + if !strings.EqualFold(os.Getenv(config.Config.Box.RunInDocker.AoSpaceSingleDockerModeEnv), "true") { + go upgrade.CheckUpgradeSucc() + } + + // 日志目录监控 + log_dir_monitor.Start() + + if err := leveldb.OpenDB(); err != nil { + fmt.Printf("\nFailed leveldb.OpenDB, err:%v\n", err) + os.Exit(0) + } + + quitChan := make(chan os.Signal) + signal.Notify(quitChan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, + syscall.SIGQUIT, syscall.SIGUSR1, syscall.SIGUSR2) + + for s := range quitChan { + switch s { + case syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT: + fmt.Printf("signal %v\n", s) + GracefullExit() + case syscall.SIGUSR1: + // fmt.Println("usr1 signal", s) + case syscall.SIGUSR2: + // fmt.Println("usr2 signal", s) + default: + // fmt.Println("other signal", s) + } + } + +} + +func GracefullExit() { + os.Exit(0) +}