From 33c4b8bba9e4bc7e31913ee9b9c11224d866a51a Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:18:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E5=AE=89=E8=A3=85=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=B2=A1=E6=9C=89=E6=AD=A3=E7=A1=AE=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98=20(#5295)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/5289 --- backend/app/service/app.go | 2 +- backend/app/service/app_install.go | 17 ++++++++--------- backend/app/service/app_utils.go | 20 +++++++++++++++----- backend/app/service/website.go | 2 +- backend/constant/app.go | 2 +- frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/tw.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + 8 files changed, 29 insertions(+), 17 deletions(-) diff --git a/backend/app/service/app.go b/backend/app/service/app.go index 6e538877d..8bafd3867 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -460,7 +460,7 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) ( go func() { defer func() { if err != nil { - appInstall.Status = constant.Error + appInstall.Status = constant.UpErr appInstall.Message = err.Error() _ = appInstallRepo.Save(context.Background(), appInstall) } diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index a51cbaa65..693f9fe83 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -153,7 +153,7 @@ func (a *AppInstallService) CheckExist(req request.AppInstalledInfo) (*response. if reflect.DeepEqual(appInstall, model.AppInstall{}) { return res, nil } - if err = syncAppInstallStatus(&appInstall); err != nil { + if err = syncAppInstallStatus(&appInstall, false); err != nil { return nil, err } @@ -244,26 +244,26 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error { if err != nil { return handleErr(install, err, out) } - return syncAppInstallStatus(&install) + return syncAppInstallStatus(&install, false) case constant.Stop: out, err := compose.Stop(dockerComposePath) if err != nil { return handleErr(install, err, out) } - return syncAppInstallStatus(&install) + return syncAppInstallStatus(&install, false) case constant.Restart: out, err := compose.Restart(dockerComposePath) if err != nil { return handleErr(install, err, out) } - return syncAppInstallStatus(&install) + return syncAppInstallStatus(&install, false) case constant.Delete: if err := deleteAppInstall(install, req.DeleteBackup, req.ForceDelete, req.DeleteDB); err != nil && !req.ForceDelete { return err } return nil case constant.Sync: - return syncAppInstallStatus(&install) + return syncAppInstallStatus(&install, true) case constant.Upgrade: upgradeReq := request.AppInstallUpgrade{ InstallID: install.ID, @@ -431,7 +431,7 @@ func (a *AppInstallService) SyncAll(systemInit bool) error { continue } if !systemInit { - if err = syncAppInstallStatus(&i); err != nil { + if err = syncAppInstallStatus(&i, false); err != nil { global.LOG.Errorf("sync install app[%s] error,mgs: %s", i.Name, err.Error()) } } @@ -730,7 +730,7 @@ func (a *AppInstallService) GetParams(id uint) (*response.AppConfig, error) { return &res, nil } -func syncAppInstallStatus(appInstall *model.AppInstall) error { +func syncAppInstallStatus(appInstall *model.AppInstall, force bool) error { if appInstall.Status == constant.Installing || appInstall.Status == constant.Rebuilding || appInstall.Status == constant.Upgrading { return nil } @@ -753,8 +753,7 @@ func syncAppInstallStatus(appInstall *model.AppInstall) error { for _, con := range containers { containersMap[con.Names[0]] = con } - synAppInstall(containersMap, appInstall) - _ = appInstallRepo.Save(context.Background(), appInstall) + synAppInstall(containersMap, appInstall, force) return nil } diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index cd8b7a01c..1a548d54a 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -929,7 +929,7 @@ func upApp(appInstall *model.AppInstall, pullImages bool) { return } if err := upProject(appInstall); err != nil { - appInstall.Status = constant.Error + appInstall.Status = constant.UpErr } else { appInstall.Status = constant.Running } @@ -1137,18 +1137,22 @@ func handleErr(install model.AppInstall, err error, out string) error { install.Message = out reErr = errors.New(out) } - install.Status = constant.Error + install.Status = constant.UpErr _ = appInstallRepo.Save(context.Background(), &install) return reErr } func doNotNeedSync(installed model.AppInstall) bool { - return installed.Status == constant.Installing || installed.Status == constant.Rebuilding || installed.Status == constant.Upgrading || installed.Status == constant.Syncing + return installed.Status == constant.Installing || installed.Status == constant.Rebuilding || installed.Status == constant.Upgrading || + installed.Status == constant.Syncing } -func synAppInstall(containers map[string]types.Container, appInstall *model.AppInstall) { +func synAppInstall(containers map[string]types.Container, appInstall *model.AppInstall, force bool) { containerNames := strings.Split(appInstall.ContainerName, ",") if len(containers) == 0 { + if appInstall.Status == constant.UpErr && !force { + return + } appInstall.Status = constant.Error appInstall.Message = buserr.WithName("ErrContainerNotFound", strings.Join(containerNames, ",")).Error() _ = appInstallRepo.Save(context.Background(), appInstall) @@ -1182,6 +1186,12 @@ func synAppInstall(containers map[string]types.Container, appInstall *model.AppI appInstall.Status = constant.Running case pausedCount == total: appInstall.Status = constant.Paused + case len(notFoundNames) == total: + if appInstall.Status == constant.UpErr && !force { + return + } + appInstall.Status = constant.Error + appInstall.Message = buserr.WithName("ErrContainerNotFound", strings.Join(notFoundNames, ",")).Error() default: var msg string if exitedCount > 0 { @@ -1225,7 +1235,7 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) continue } if sync && !doNotNeedSync(installed) { - synAppInstall(containersMap, &installed) + synAppInstall(containersMap, &installed, false) } installDTO := response.AppInstallDTO{ diff --git a/backend/app/service/website.go b/backend/app/service/website.go index 1744f3320..ac5512d1a 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -948,7 +948,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r if len(checkIds) > 0 { installList, _ := appInstallRepo.ListBy(commonRepo.WithIdsIn(checkIds)) for _, install := range installList { - if err = syncAppInstallStatus(&install); err != nil { + if err = syncAppInstallStatus(&install, false); err != nil { return nil, err } res = append(res, response.WebsitePreInstallCheck{ diff --git a/backend/constant/app.go b/backend/constant/app.go index 4e4f8d6e1..9a6f5c825 100644 --- a/backend/constant/app.go +++ b/backend/constant/app.go @@ -13,7 +13,7 @@ const ( Syncing = "Syncing" SyncSuccess = "SyncSuccess" Paused = "Paused" - SyncErr = "SyncErr" + UpErr = "UpErr" ContainerPrefix = "1Panel-" diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index e910f1661..ac5b7c140 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -263,6 +263,7 @@ const message = { applying: 'Applying', applyerror: 'Failure', syncerr: 'Error', + uperr: 'Error', }, units: { second: 'Second', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index b6c5823be..d7c000a01 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -261,6 +261,7 @@ const message = { applying: '申請中', applyerror: '失敗', syncerr: '失敗', + uperr: '失败', }, units: { second: '秒', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index e56d2083c..37c893a06 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -261,6 +261,7 @@ const message = { applying: '申请中', applyerror: '失败', syncerr: '失败', + uperr: '失败', }, units: { second: '秒',