Skip to content

Commit

Permalink
fix mount dir
Browse files Browse the repository at this point in the history
  • Loading branch information
zxln007 committed Apr 11, 2024
1 parent 1bbac73 commit 24a2fb9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 47 deletions.
87 changes: 47 additions & 40 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,57 @@ func init() {
Config.Version = v
if !v {
modifyConfigWhenRunInDocker()
mountPath := hardware_util.GetMountDir()
if mountPath != "" {
JoinMountPathInConfigPath(mountPath)
}
createLogFileDir()
writeDefaultConfigFile(*flagConfFile)
}
}

func JoinMountPathInConfigPath(mountPath string) {
p := []*string{
&Config.Log.AoLogDirBase,
&Config.Log.Path,
&Config.Box.CpuIdStoreFile,
&Config.Box.SnNumberStoreFile,
&Config.Box.HostIpFile,
&Config.Box.ApplyEmailStoreFile,
&Config.Box.BoxInfoFile,
&Config.Box.InternetServiceConfigFile,

&Config.Box.SwithStatusFile,
&Config.Box.WifiNamePasswdFile,
&Config.Box.BoxMetaAdminPair,
&Config.Box.RandDockercomposePassword,
&Config.Box.RandDockercomposeRedisPort,

&Config.Box.PublicSharedInfoFile,
&Config.Box.BoxKey.RsaKeyFile,
&Config.Box.BoxKey.RsaPubKeyFile,
&Config.Box.Disk.DiskInitialInfoFile,
&Config.Box.Disk.DeviceUuidRecordFile,
&Config.Box.Disk.DiskSharedInfoFile,
&Config.Box.ClientKey.RsaPubKeyFile,
&Config.Box.ClientKey.RsaPriKeyFile,
&Config.Box.ClientKey.SharedSecret,
&Config.Box.UpgradeConfig.SettingsFile,
&Config.Box.Cert.CertDir,
&Config.Docker.ComposeFile,
&Config.Docker.CustomComposeFile,
&Config.RunTime.BasePath,
&Config.Notification.UpgradeRecordFile,
&Config.Box.Disk.StorageVolumePath,
&Config.Box.Disk.NoDisksFileStoragePath,
&Config.Box.Disk.NoDisksFileStoragePathDockerDeploy,
&Config.GTClient.ConfigPath,
&Config.Box.DID.RootPath}
for _, v := range p {
*v = mountPath + *v
}
}

func modifyConfigWhenRunInDocker() {
// fmt.Printf("+++++++++++++++++++++++ modifyConfigWhenRunInDocker \n")
////////////////////////////////////////////////////////////
Expand All @@ -453,46 +499,7 @@ func modifyConfigWhenRunInDocker() {
// 修改保存路径。
// 新增路径的配置项时,如果docker 中运行时, 需要在这里修改默认路径 !!!
if runInDocker {
p := []*string{
&Config.Log.AoLogDirBase,
&Config.Log.Path,
&Config.Box.CpuIdStoreFile,
&Config.Box.SnNumberStoreFile,
&Config.Box.HostIpFile,
&Config.Box.ApplyEmailStoreFile,
&Config.Box.BoxInfoFile,
&Config.Box.InternetServiceConfigFile,

&Config.Box.SwithStatusFile,
&Config.Box.WifiNamePasswdFile,
&Config.Box.BoxMetaAdminPair,
&Config.Box.RandDockercomposePassword,
&Config.Box.RandDockercomposeRedisPort,

&Config.Box.PublicSharedInfoFile,
&Config.Box.BoxKey.RsaKeyFile,
&Config.Box.BoxKey.RsaPubKeyFile,
&Config.Box.Disk.DiskInitialInfoFile,
&Config.Box.Disk.DeviceUuidRecordFile,
&Config.Box.Disk.DiskSharedInfoFile,
&Config.Box.ClientKey.RsaPubKeyFile,
&Config.Box.ClientKey.RsaPriKeyFile,
&Config.Box.ClientKey.SharedSecret,
&Config.Box.UpgradeConfig.SettingsFile,
&Config.Box.Cert.CertDir,
&Config.Docker.ComposeFile,
&Config.Docker.CustomComposeFile,
&Config.RunTime.BasePath,
&Config.Notification.UpgradeRecordFile,
&Config.Box.Disk.StorageVolumePath,
&Config.Box.Disk.NoDisksFileStoragePath,
&Config.Box.Disk.NoDisksFileStoragePathDockerDeploy,
&Config.GTClient.ConfigPath,
&Config.Box.DID.RootPath}

for _, v := range p {
*v = SpaceMountPath + *v
}

// fmt.Printf("Config.Box.SnNumberStoreFile: %v \n", Config.Box.SnNumberStoreFile)

// 调用地址修改
Expand Down
14 changes: 7 additions & 7 deletions utils/hardware/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func GetHardwareChip() (string, error) {
// RunningInDocker is program running in container ?
func RunningInDocker() bool {
// 由于其他方法在某些 OS 上有失效的可能性,暂时用用户传入的环境变量来判断。
envkey := "AOSPACE_DATADIR"
dataDir := os.Getenv(envkey)
if len(dataDir) > 0 {
// fmt.Printf("RunningInDocker, dataDir:%v\n", dataDir)
return true
} else {
// fmt.Printf("RunningInDocker==false, dataDir:%v\n", dataDir)
_, err := os.Stat("/root/.dockerenv")
if err != nil {
return false
}
return true
}

func GetMountDir() string {
return os.Getenv("AOSPACE_DATADIR")
}

0 comments on commit 24a2fb9

Please sign in to comment.