mirror of
				https://github.com/1Panel-dev/1Panel.git
				synced 2025-11-04 07:17:39 +08:00 
			
		
		
		
	fix: 端口改为从配置文件随机生成
This commit is contained in:
		
							parent
							
								
									3f01ef61e5
								
							
						
					
					
						commit
						68db3cf389
					
				
					 2 changed files with 16 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue