Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复启动时的网关环境变量问题和缺失aofs磁盘文件问题 #32

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,17 @@ func modifyConfigWhenRunInDocker() {
*v = strings.ReplaceAll(*v, "localhost:8080", "aospace-gateway:8080")
*v = strings.ReplaceAll(*v, "127.0.0.1:6379", "aospace-redis:6379")
}
}
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"

// All
Config.GateWay.LanPort = 12841
Config.GateWay.TlsLanPort = 18569
Config.GateWay.LanPort = 80
Config.GateWay.TlsLanPort = 443
}

}
// fmt.Printf("######################## Config.Log.Path:%v\n",
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)
}