From 68db3cf389680aae40f0c127bba7fc885f04d1d9 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Fri, 10 Mar 2023 13:47:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AB=AF=E5=8F=A3=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E4=BB=8E=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/init/migration/migrations/init.go | 2 +- backend/init/viper/viper.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/init/migration/migrations/init.go b/backend/init/migration/migrations/init.go index 2253612e9..dec649f4c 100644 --- a/backend/init/migration/migrations/init.go +++ b/backend/init/migration/migrations/init.go @@ -88,7 +88,7 @@ var AddTableSetting = &gormigrate.Migration{ return err } - if err := tx.Create(&model.Setting{Key: "ServerPort", Value: "9999"}).Error; err != nil { + if err := tx.Create(&model.Setting{Key: "ServerPort", Value: global.CONF.System.Port}).Error; err != nil { return err } if err := tx.Create(&model.Setting{Key: "SecurityEntrance", Value: "onepanel"}).Error; err != nil { diff --git a/backend/init/viper/viper.go b/backend/init/viper/viper.go index 186adfa31..5ad06c87e 100644 --- a/backend/init/viper/viper.go +++ b/backend/init/viper/viper.go @@ -18,6 +18,7 @@ import ( func Init() { baseDir := "/opt" + port := "9999" mode := "" fileOp := files.NewFileOp() v := viper.NewWithOptions() @@ -45,6 +46,16 @@ func Init() { if len(baseDir) == 0 { panic("error `BASE_DIR` find in /usr/bin/1pctl") } + + stdoutPort, err := cmd.Exec("grep '^PANEL_PORT=' /usr/bin/1pctl | cut -d'=' -f2") + if err != nil { + panic(err) + } + port = strings.ReplaceAll(stdoutPort, "\n", "") + if len(port) == 0 { + panic("error `PANEL_PORT` find in /usr/bin/1pctl") + } + if strings.HasSuffix(baseDir, "/") { baseDir = baseDir[:strings.LastIndex(baseDir, "/")] } @@ -65,6 +76,9 @@ func Init() { if mode == "dev" && fileOp.Stat("/opt/1panel/conf/app.yaml") && serverConfig.System.BaseDir != "" { baseDir = serverConfig.System.BaseDir } + if mode == "dev" && fileOp.Stat("/opt/1panel/conf/app.yaml") && serverConfig.System.Port != "" { + port = serverConfig.System.Port + } global.CONF = serverConfig global.CONF.BaseDir = baseDir @@ -75,5 +89,6 @@ func Init() { global.CONF.System.DbPath = global.CONF.System.DataDir + "/db" global.CONF.System.LogPath = global.CONF.System.DataDir + "/log" global.CONF.System.TmpDir = global.CONF.System.DataDir + "/tmp" + global.CONF.System.Port = port global.Viper = v }