diff --git a/backend/init/viper/viper.go b/backend/init/viper/viper.go index 0fa56dda3..ccb93b745 100644 --- a/backend/init/viper/viper.go +++ b/backend/init/viper/viper.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "github.com/1Panel-dev/1Panel/backend/utils/files" + "gopkg.in/yaml.v3" "path" "strings" @@ -18,18 +19,28 @@ import ( func Init() { baseDir := "/opt" - mode := "local" + mode := "dev" fileOp := files.NewFileOp() v := viper.NewWithOptions() v.SetConfigType("yaml") - if fileOp.Stat("/opt/1panel/conf/app.yaml") { + + config := configs.ServerConfig{} + if err := yaml.Unmarshal(conf.AppYaml, &config); err != nil { + panic(err) + } + if config.System.Mode != "" { + mode = config.System.Mode + } + if mode != "release" { + if !fileOp.Stat("/opt/1panel/conf/app.yaml") { + panic("conf file is not exist") + } v.SetConfigName("app") v.AddConfigPath(path.Join("/opt/1panel/conf")) if err := v.ReadInConfig(); err != nil { panic(fmt.Errorf("Fatal error config file: %s \n", err)) } } else { - mode = "release" stdout, err := cmd.Exec("grep '^BASE_DIR=' /usr/bin/1pctl | cut -d'=' -f2") if err != nil { panic(err) @@ -52,7 +63,7 @@ func Init() { if err := v.Unmarshal(&serverConfig); err != nil { panic(err) } - if mode == "local" && serverConfig.System.BaseDir != "" { + if mode != "release" && serverConfig.System.BaseDir != "" { baseDir = serverConfig.System.BaseDir } global.CONF = serverConfig diff --git a/cmd/server/conf/app.yaml b/cmd/server/conf/app.yaml index b821a0fca..e7e6b9ac4 100644 --- a/cmd/server/conf/app.yaml +++ b/cmd/server/conf/app.yaml @@ -3,6 +3,7 @@ system: app_repo_owner: 1Panel-dev app_repo_name: appstore base_dir: /opt + mode: dev log: level: debug