mirror of https://github.com/1Panel-dev/1Panel
feat: 修改应用端口,同时修改网站配置
parent
25149bbede
commit
3bd20e5b28
|
@ -3,6 +3,7 @@ package service
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/utils/nginx"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
|
@ -199,10 +200,12 @@ func (a AppInstallService) Update(req request.AppInstalledUpdate) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
changePort := false
|
||||||
port, ok := req.Params["PANEL_APP_PORT_HTTP"]
|
port, ok := req.Params["PANEL_APP_PORT_HTTP"]
|
||||||
if ok {
|
if ok {
|
||||||
portN := int(math.Ceil(port.(float64)))
|
portN := int(math.Ceil(port.(float64)))
|
||||||
if portN != installed.HttpPort {
|
if portN != installed.HttpPort {
|
||||||
|
changePort = true
|
||||||
httpPort, err := checkPort("PANEL_APP_PORT_HTTP", req.Params)
|
httpPort, err := checkPort("PANEL_APP_PORT_HTTP", req.Params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -237,7 +240,33 @@ func (a AppInstallService) Update(req request.AppInstalledUpdate) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_ = appInstallRepo.Save(&installed)
|
_ = appInstallRepo.Save(&installed)
|
||||||
return rebuildApp(installed)
|
|
||||||
|
if err := rebuildApp(installed); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
website, _ := websiteRepo.GetFirst(websiteRepo.WithAppInstallId(installed.ID))
|
||||||
|
if changePort && website.ID != 0 && website.Status == constant.Running {
|
||||||
|
nginxInstall, err := getNginxFull(&website)
|
||||||
|
if err != nil {
|
||||||
|
return buserr.WithErr(constant.ErrUpdateBuWebsite, err)
|
||||||
|
}
|
||||||
|
config := nginxInstall.SiteConfig.Config
|
||||||
|
servers := config.FindServers()
|
||||||
|
if len(servers) == 0 {
|
||||||
|
return buserr.WithErr(constant.ErrUpdateBuWebsite, errors.New("nginx config is not valid"))
|
||||||
|
}
|
||||||
|
server := servers[0]
|
||||||
|
proxy := fmt.Sprintf("http://127.0.0.1:%d", installed.HttpPort)
|
||||||
|
server.UpdateRootProxy([]string{proxy})
|
||||||
|
|
||||||
|
if err := nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
|
||||||
|
return buserr.WithErr(constant.ErrUpdateBuWebsite, err)
|
||||||
|
}
|
||||||
|
if err := nginxCheckAndReload(nginxInstall.SiteConfig.OldContent, config.FilePath, nginxInstall.Install.ContainerName); err != nil {
|
||||||
|
return buserr.WithErr(constant.ErrUpdateBuWebsite, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) SyncAll() error {
|
func (a AppInstallService) SyncAll() error {
|
||||||
|
|
|
@ -46,6 +46,14 @@ func WithDetail(Key string, detail interface{}, err error) BusinessError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithErr(Key string, err error) BusinessError {
|
||||||
|
return BusinessError{
|
||||||
|
Msg: Key,
|
||||||
|
Detail: "",
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WithMap(Key string, maps map[string]interface{}, err error) BusinessError {
|
func WithMap(Key string, maps map[string]interface{}, err error) BusinessError {
|
||||||
return BusinessError{
|
return BusinessError{
|
||||||
Msg: Key,
|
Msg: Key,
|
||||||
|
|
|
@ -50,14 +50,15 @@ var (
|
||||||
|
|
||||||
// app
|
// app
|
||||||
var (
|
var (
|
||||||
ErrPortInUsed = "ErrPortInUsed"
|
ErrPortInUsed = "ErrPortInUsed"
|
||||||
ErrAppLimit = "ErrAppLimit"
|
ErrAppLimit = "ErrAppLimit"
|
||||||
ErrAppRequired = "ErrAppRequired"
|
ErrAppRequired = "ErrAppRequired"
|
||||||
ErrFileCanNotRead = "ErrFileCanNotRead"
|
ErrFileCanNotRead = "ErrFileCanNotRead"
|
||||||
ErrFileToLarge = "ErrFileToLarge"
|
ErrFileToLarge = "ErrFileToLarge"
|
||||||
ErrNotInstall = "ErrNotInstall"
|
ErrNotInstall = "ErrNotInstall"
|
||||||
ErrPortInOtherApp = "ErrPortInOtherApp"
|
ErrPortInOtherApp = "ErrPortInOtherApp"
|
||||||
ErrDbUserNotValid = "ErrDbUserNotValid"
|
ErrDbUserNotValid = "ErrDbUserNotValid"
|
||||||
|
ErrUpdateBuWebsite = "ErrUpdateBuWebsite"
|
||||||
)
|
)
|
||||||
|
|
||||||
//website
|
//website
|
||||||
|
|
|
@ -25,6 +25,7 @@ ErrNotInstall: "App not installed"
|
||||||
ErrPortInOtherApp: "{{ .port }} port already in use by {{ .apps }}"
|
ErrPortInOtherApp: "{{ .port }} port already in use by {{ .apps }}"
|
||||||
ErrDbUserNotValid: "Stock database, username and password do not match!"
|
ErrDbUserNotValid: "Stock database, username and password do not match!"
|
||||||
ErrDockerComposeNotValid: "docker-compose file format error!"
|
ErrDockerComposeNotValid: "docker-compose file format error!"
|
||||||
|
ErrUpdateBuWebsite: 'The application was updated successfully, but the modification of the website configuration file failed, please check the configuration!'
|
||||||
|
|
||||||
#file
|
#file
|
||||||
ErrFileCanNotRead: "File can not read"
|
ErrFileCanNotRead: "File can not read"
|
||||||
|
|
|
@ -25,6 +25,7 @@ ErrNotInstall: "应用未安装"
|
||||||
ErrPortInOtherApp: "{{ .port }} 端口已被 {{ .apps }}占用!"
|
ErrPortInOtherApp: "{{ .port }} 端口已被 {{ .apps }}占用!"
|
||||||
ErrDbUserNotValid: "存量数据库,用户名密码不匹配!"
|
ErrDbUserNotValid: "存量数据库,用户名密码不匹配!"
|
||||||
ErrDockerComposeNotValid: "docker-compose 文件格式错误"
|
ErrDockerComposeNotValid: "docker-compose 文件格式错误"
|
||||||
|
ErrUpdateBuWebsite: '应用更新成功,但是网站配置文件修改失败,请检查配置!'
|
||||||
|
|
||||||
#file
|
#file
|
||||||
ErrFileCanNotRead: "此文件不支持预览"
|
ErrFileCanNotRead: "此文件不支持预览"
|
||||||
|
|
Loading…
Reference in New Issue