Skip to content

Commit

Permalink
修复单容器启动时磁盘信息文件;修复单容器启动时环境变量地址问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
jack30724 committed Dec 3, 2024
1 parent b919cd2 commit 1be7517
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 102 deletions.
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ func modifyConfigWhenRunInDocker() {
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
}
Expand Down
205 changes: 103 additions & 102 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

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)
}

0 comments on commit 1be7517

Please sign in to comment.