mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-14 01:34:47 +08:00
fix: 端口改为从配置文件随机生成
This commit is contained in:
parent
3f01ef61e5
commit
68db3cf389
@ -88,7 +88,7 @@ var AddTableSetting = &gormigrate.Migration{
|
|||||||
return err
|
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
|
return err
|
||||||
}
|
}
|
||||||
if err := tx.Create(&model.Setting{Key: "SecurityEntrance", Value: "onepanel"}).Error; err != nil {
|
if err := tx.Create(&model.Setting{Key: "SecurityEntrance", Value: "onepanel"}).Error; err != nil {
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
baseDir := "/opt"
|
baseDir := "/opt"
|
||||||
|
port := "9999"
|
||||||
mode := ""
|
mode := ""
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
v := viper.NewWithOptions()
|
v := viper.NewWithOptions()
|
||||||
@ -45,6 +46,16 @@ func Init() {
|
|||||||
if len(baseDir) == 0 {
|
if len(baseDir) == 0 {
|
||||||
panic("error `BASE_DIR` find in /usr/bin/1pctl")
|
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, "/") {
|
if strings.HasSuffix(baseDir, "/") {
|
||||||
baseDir = baseDir[:strings.LastIndex(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 != "" {
|
if mode == "dev" && fileOp.Stat("/opt/1panel/conf/app.yaml") && serverConfig.System.BaseDir != "" {
|
||||||
baseDir = 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 = serverConfig
|
||||||
global.CONF.BaseDir = baseDir
|
global.CONF.BaseDir = baseDir
|
||||||
@ -75,5 +89,6 @@ func Init() {
|
|||||||
global.CONF.System.DbPath = global.CONF.System.DataDir + "/db"
|
global.CONF.System.DbPath = global.CONF.System.DataDir + "/db"
|
||||||
global.CONF.System.LogPath = global.CONF.System.DataDir + "/log"
|
global.CONF.System.LogPath = global.CONF.System.DataDir + "/log"
|
||||||
global.CONF.System.TmpDir = global.CONF.System.DataDir + "/tmp"
|
global.CONF.System.TmpDir = global.CONF.System.DataDir + "/tmp"
|
||||||
|
global.CONF.System.Port = port
|
||||||
global.Viper = v
|
global.Viper = v
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user