From fa1e945b8dbc905e990c5a8df1dbb9beb7d90dd7 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:55:02 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E5=A4=84=E7=90=86=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=AD=A6=E5=91=8A=20(#4036)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/app_install.go | 4 +- backend/app/service/app_utils.go | 46 ++++++++++------------ backend/app/service/database_mysql.go | 4 +- backend/app/service/database_postgresql.go | 4 +- backend/app/service/database_redis.go | 4 +- backend/app/service/setting.go | 4 +- backend/app/service/upgrade.go | 10 ++--- backend/app/service/website_utils.go | 19 ++++----- 8 files changed, 46 insertions(+), 49 deletions(-) diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index 6d7328579..cd9df9764 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -527,7 +527,7 @@ func (a *AppInstallService) ChangeAppPort(req request.PortUpdate) error { return nil } - if err := updateInstallInfoInDB(req.Key, req.Name, "port", true, strconv.FormatInt(req.Port, 10)); err != nil { + if err := updateInstallInfoInDB(req.Key, req.Name, "port", strconv.FormatInt(req.Port, 10)); err != nil { return nil } @@ -776,7 +776,7 @@ func syncAppInstallStatus(appInstall *model.AppInstall) error { return nil } -func updateInstallInfoInDB(appKey, appName, param string, isRestart bool, value interface{}) error { +func updateInstallInfoInDB(appKey, appName, param string, value interface{}) error { if param != "password" && param != "port" && param != "user-password" { return nil } diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index 797804241..4e22f9266 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -849,38 +849,34 @@ func checkContainerNameIsExist(containerName, appDir string) (bool, error) { func upApp(appInstall *model.AppInstall, pullImages bool) { upProject := func(appInstall *model.AppInstall) (err error) { - if err == nil { - var ( - out string - errMsg string - ) - if pullImages && appInstall.App.Type != "php" { - out, err = compose.Pull(appInstall.GetComposePath()) - if err != nil { - if out != "" { - if strings.Contains(out, "no such host") { - errMsg = i18n.GetMsgByKey("ErrNoSuchHost") + ":" - } - if strings.Contains(out, "timeout") { - errMsg = i18n.GetMsgByKey("ErrImagePullTimeOut") + ":" - } - appInstall.Message = errMsg + out - } - return err - } - } - - out, err = compose.Up(appInstall.GetComposePath()) + var ( + out string + errMsg string + ) + if pullImages && appInstall.App.Type != "php" { + out, err = compose.Pull(appInstall.GetComposePath()) if err != nil { if out != "" { + if strings.Contains(out, "no such host") { + errMsg = i18n.GetMsgByKey("ErrNoSuchHost") + ":" + } + if strings.Contains(out, "timeout") { + errMsg = i18n.GetMsgByKey("ErrImagePullTimeOut") + ":" + } appInstall.Message = errMsg + out } return err } - return - } else { - return } + + out, err = compose.Up(appInstall.GetComposePath()) + if err != nil { + if out != "" { + appInstall.Message = errMsg + out + } + return err + } + return } if err := upProject(appInstall); err != nil { appInstall.Status = constant.Error diff --git a/backend/app/service/database_mysql.go b/backend/app/service/database_mysql.go index be93f006f..f46ed081c 100644 --- a/backend/app/service/database_mysql.go +++ b/backend/app/service/database_mysql.go @@ -342,7 +342,7 @@ func (u *MysqlService) ChangePassword(req dto.ChangeDBInfo) error { } global.LOG.Infof("start to update mysql password used by app %s-%s", appModel.Key, appInstall.Name) - if err := updateInstallInfoInDB(appModel.Key, appInstall.Name, "user-password", true, req.Value); err != nil { + if err := updateInstallInfoInDB(appModel.Key, appInstall.Name, "user-password", req.Value); err != nil { return err } } @@ -355,7 +355,7 @@ func (u *MysqlService) ChangePassword(req dto.ChangeDBInfo) error { return nil } - if err := updateInstallInfoInDB(req.Type, req.Database, "password", false, req.Value); err != nil { + if err := updateInstallInfoInDB(req.Type, req.Database, "password", req.Value); err != nil { return err } return nil diff --git a/backend/app/service/database_postgresql.go b/backend/app/service/database_postgresql.go index a109bee60..f9a8b080f 100644 --- a/backend/app/service/database_postgresql.go +++ b/backend/app/service/database_postgresql.go @@ -393,7 +393,7 @@ func (u *PostgresqlService) ChangePassword(req dto.ChangeDBInfo) error { } global.LOG.Infof("start to update postgresql password used by app %s-%s", appModel.Key, appInstall.Name) - if err := updateInstallInfoInDB(appModel.Key, appInstall.Name, "user-password", true, req.Value); err != nil { + if err := updateInstallInfoInDB(appModel.Key, appInstall.Name, "user-password", req.Value); err != nil { return err } } @@ -406,7 +406,7 @@ func (u *PostgresqlService) ChangePassword(req dto.ChangeDBInfo) error { return nil } - if err := updateInstallInfoInDB(req.Type, req.Database, "password", false, req.Value); err != nil { + if err := updateInstallInfoInDB(req.Type, req.Database, "password", req.Value); err != nil { return err } return nil diff --git a/backend/app/service/database_redis.go b/backend/app/service/database_redis.go index 6937cd8a0..4423e1200 100644 --- a/backend/app/service/database_redis.go +++ b/backend/app/service/database_redis.go @@ -55,10 +55,10 @@ func (u *RedisService) UpdateConf(req dto.RedisConfUpdate) error { } func (u *RedisService) ChangePassword(req dto.ChangeRedisPass) error { - if err := updateInstallInfoInDB("redis", "", "password", true, req.Value); err != nil { + if err := updateInstallInfoInDB("redis", "", "password", req.Value); err != nil { return err } - if err := updateInstallInfoInDB("redis-commander", "", "password", true, req.Value); err != nil { + if err := updateInstallInfoInDB("redis-commander", "", "password", req.Value); err != nil { return err } diff --git a/backend/app/service/setting.go b/backend/app/service/setting.go index 940e27bad..06b688182 100644 --- a/backend/app/service/setting.go +++ b/backend/app/service/setting.go @@ -280,7 +280,7 @@ func (u *SettingService) UpdateSSL(c *gin.Context, req dto.SSLUpdate) error { if err := fileOp.WriteFile(path.Join(secretDir, "server.key.tmp"), strings.NewReader(key), 0600); err != nil { return err } - if err := checkCertValid(req.Domain); err != nil { + if err := checkCertValid(); err != nil { return err } if err := fileOp.Rename(path.Join(secretDir, "server.crt.tmp"), path.Join(secretDir, "server.crt")); err != nil { @@ -418,7 +418,7 @@ func loadInfoFromCert() (*dto.SSLInfo, error) { }, nil } -func checkCertValid(domain string) error { +func checkCertValid() error { certificate, err := os.ReadFile(path.Join(global.CONF.System.BaseDir, "1panel/secret/server.crt.tmp")) if err != nil { return err diff --git a/backend/app/service/upgrade.go b/backend/app/service/upgrade.go index a58d6f63a..cab53b30e 100644 --- a/backend/app/service/upgrade.go +++ b/backend/app/service/upgrade.go @@ -133,24 +133,24 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error { if err := cpBinary([]string{tmpDir + "/1panel"}, "/usr/local/bin/1panel"); err != nil { global.LOG.Errorf("upgrade 1panel failed, err: %v", err) - u.handleRollback(fileOp, originalDir, 1) + u.handleRollback(originalDir, 1) return } if err := cpBinary([]string{tmpDir + "/1pctl"}, "/usr/local/bin/1pctl"); err != nil { global.LOG.Errorf("upgrade 1pctl failed, err: %v", err) - u.handleRollback(fileOp, originalDir, 2) + u.handleRollback(originalDir, 2) return } if _, err := cmd.Execf("sed -i -e 's#BASE_DIR=.*#BASE_DIR=%s#g' /usr/local/bin/1pctl", global.CONF.System.BaseDir); err != nil { global.LOG.Errorf("upgrade basedir in 1pctl failed, err: %v", err) - u.handleRollback(fileOp, originalDir, 2) + u.handleRollback(originalDir, 2) return } if err := cpBinary([]string{tmpDir + "/1panel.service"}, "/etc/systemd/system/1panel.service"); err != nil { global.LOG.Errorf("upgrade 1panel.service failed, err: %v", err) - u.handleRollback(fileOp, originalDir, 3) + u.handleRollback(originalDir, 3) return } @@ -181,7 +181,7 @@ func (u *UpgradeService) handleBackup(fileOp files.FileOp, originalDir string) e return nil } -func (u *UpgradeService) handleRollback(fileOp files.FileOp, originalDir string, errStep int) { +func (u *UpgradeService) handleRollback(originalDir string, errStep int) { dbPath := global.CONF.System.DbPath + "/1Panel.db" _ = settingRepo.Update("SystemStatus", "Free") if err := cpBinary([]string{originalDir + "/1Panel.db"}, dbPath); err != nil { diff --git a/backend/app/service/website_utils.go b/backend/app/service/website_utils.go index b7a988207..3a96fe811 100644 --- a/backend/app/service/website_utils.go +++ b/backend/app/service/website_utils.go @@ -2,13 +2,6 @@ package service import ( "fmt" - "github.com/1Panel-dev/1Panel/backend/buserr" - "github.com/1Panel-dev/1Panel/backend/global" - "github.com/1Panel-dev/1Panel/backend/i18n" - "github.com/1Panel-dev/1Panel/backend/utils/cmd" - "github.com/1Panel-dev/1Panel/backend/utils/common" - "github.com/1Panel-dev/1Panel/backend/utils/nginx/components" - "gopkg.in/yaml.v3" "log" "os" "path" @@ -18,6 +11,14 @@ import ( "strings" "time" + "github.com/1Panel-dev/1Panel/backend/buserr" + "github.com/1Panel-dev/1Panel/backend/global" + "github.com/1Panel-dev/1Panel/backend/i18n" + "github.com/1Panel-dev/1Panel/backend/utils/cmd" + "github.com/1Panel-dev/1Panel/backend/utils/common" + "github.com/1Panel-dev/1Panel/backend/utils/nginx/components" + "gopkg.in/yaml.v3" + "github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/dto" @@ -114,7 +115,7 @@ func createIndexFile(website *model.Website, runtime *model.Runtime) error { return nil } -func createProxyFile(website *model.Website, runtime *model.Runtime) error { +func createProxyFile(website *model.Website) error { nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) if err != nil { return err @@ -191,7 +192,7 @@ func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website, } } if website.Type == constant.Proxy { - if err := createProxyFile(website, runtime); err != nil { + if err := createProxyFile(website); err != nil { return err } }