mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
fix: 解决某些情况下安装应用错误没有正确显示的问题 (#5295)
Refs https://github.com/1Panel-dev/1Panel/issues/5289
This commit is contained in:
parent
296ae1c2e1
commit
33c4b8bba9
@ -460,7 +460,7 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) (
|
|||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
appInstall.Status = constant.Error
|
appInstall.Status = constant.UpErr
|
||||||
appInstall.Message = err.Error()
|
appInstall.Message = err.Error()
|
||||||
_ = appInstallRepo.Save(context.Background(), appInstall)
|
_ = appInstallRepo.Save(context.Background(), appInstall)
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func (a *AppInstallService) CheckExist(req request.AppInstalledInfo) (*response.
|
|||||||
if reflect.DeepEqual(appInstall, model.AppInstall{}) {
|
if reflect.DeepEqual(appInstall, model.AppInstall{}) {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
if err = syncAppInstallStatus(&appInstall); err != nil {
|
if err = syncAppInstallStatus(&appInstall, false); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,26 +244,26 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return handleErr(install, err, out)
|
return handleErr(install, err, out)
|
||||||
}
|
}
|
||||||
return syncAppInstallStatus(&install)
|
return syncAppInstallStatus(&install, false)
|
||||||
case constant.Stop:
|
case constant.Stop:
|
||||||
out, err := compose.Stop(dockerComposePath)
|
out, err := compose.Stop(dockerComposePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return handleErr(install, err, out)
|
return handleErr(install, err, out)
|
||||||
}
|
}
|
||||||
return syncAppInstallStatus(&install)
|
return syncAppInstallStatus(&install, false)
|
||||||
case constant.Restart:
|
case constant.Restart:
|
||||||
out, err := compose.Restart(dockerComposePath)
|
out, err := compose.Restart(dockerComposePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return handleErr(install, err, out)
|
return handleErr(install, err, out)
|
||||||
}
|
}
|
||||||
return syncAppInstallStatus(&install)
|
return syncAppInstallStatus(&install, false)
|
||||||
case constant.Delete:
|
case constant.Delete:
|
||||||
if err := deleteAppInstall(install, req.DeleteBackup, req.ForceDelete, req.DeleteDB); err != nil && !req.ForceDelete {
|
if err := deleteAppInstall(install, req.DeleteBackup, req.ForceDelete, req.DeleteDB); err != nil && !req.ForceDelete {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
case constant.Sync:
|
case constant.Sync:
|
||||||
return syncAppInstallStatus(&install)
|
return syncAppInstallStatus(&install, true)
|
||||||
case constant.Upgrade:
|
case constant.Upgrade:
|
||||||
upgradeReq := request.AppInstallUpgrade{
|
upgradeReq := request.AppInstallUpgrade{
|
||||||
InstallID: install.ID,
|
InstallID: install.ID,
|
||||||
@ -431,7 +431,7 @@ func (a *AppInstallService) SyncAll(systemInit bool) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !systemInit {
|
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())
|
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
|
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 {
|
if appInstall.Status == constant.Installing || appInstall.Status == constant.Rebuilding || appInstall.Status == constant.Upgrading {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -753,8 +753,7 @@ func syncAppInstallStatus(appInstall *model.AppInstall) error {
|
|||||||
for _, con := range containers {
|
for _, con := range containers {
|
||||||
containersMap[con.Names[0]] = con
|
containersMap[con.Names[0]] = con
|
||||||
}
|
}
|
||||||
synAppInstall(containersMap, appInstall)
|
synAppInstall(containersMap, appInstall, force)
|
||||||
_ = appInstallRepo.Save(context.Background(), appInstall)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -929,7 +929,7 @@ func upApp(appInstall *model.AppInstall, pullImages bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := upProject(appInstall); err != nil {
|
if err := upProject(appInstall); err != nil {
|
||||||
appInstall.Status = constant.Error
|
appInstall.Status = constant.UpErr
|
||||||
} else {
|
} else {
|
||||||
appInstall.Status = constant.Running
|
appInstall.Status = constant.Running
|
||||||
}
|
}
|
||||||
@ -1137,18 +1137,22 @@ func handleErr(install model.AppInstall, err error, out string) error {
|
|||||||
install.Message = out
|
install.Message = out
|
||||||
reErr = errors.New(out)
|
reErr = errors.New(out)
|
||||||
}
|
}
|
||||||
install.Status = constant.Error
|
install.Status = constant.UpErr
|
||||||
_ = appInstallRepo.Save(context.Background(), &install)
|
_ = appInstallRepo.Save(context.Background(), &install)
|
||||||
return reErr
|
return reErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func doNotNeedSync(installed model.AppInstall) bool {
|
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, ",")
|
containerNames := strings.Split(appInstall.ContainerName, ",")
|
||||||
if len(containers) == 0 {
|
if len(containers) == 0 {
|
||||||
|
if appInstall.Status == constant.UpErr && !force {
|
||||||
|
return
|
||||||
|
}
|
||||||
appInstall.Status = constant.Error
|
appInstall.Status = constant.Error
|
||||||
appInstall.Message = buserr.WithName("ErrContainerNotFound", strings.Join(containerNames, ",")).Error()
|
appInstall.Message = buserr.WithName("ErrContainerNotFound", strings.Join(containerNames, ",")).Error()
|
||||||
_ = appInstallRepo.Save(context.Background(), appInstall)
|
_ = appInstallRepo.Save(context.Background(), appInstall)
|
||||||
@ -1182,6 +1186,12 @@ func synAppInstall(containers map[string]types.Container, appInstall *model.AppI
|
|||||||
appInstall.Status = constant.Running
|
appInstall.Status = constant.Running
|
||||||
case pausedCount == total:
|
case pausedCount == total:
|
||||||
appInstall.Status = constant.Paused
|
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:
|
default:
|
||||||
var msg string
|
var msg string
|
||||||
if exitedCount > 0 {
|
if exitedCount > 0 {
|
||||||
@ -1225,7 +1235,7 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool)
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if sync && !doNotNeedSync(installed) {
|
if sync && !doNotNeedSync(installed) {
|
||||||
synAppInstall(containersMap, &installed)
|
synAppInstall(containersMap, &installed, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
installDTO := response.AppInstallDTO{
|
installDTO := response.AppInstallDTO{
|
||||||
|
@ -948,7 +948,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r
|
|||||||
if len(checkIds) > 0 {
|
if len(checkIds) > 0 {
|
||||||
installList, _ := appInstallRepo.ListBy(commonRepo.WithIdsIn(checkIds))
|
installList, _ := appInstallRepo.ListBy(commonRepo.WithIdsIn(checkIds))
|
||||||
for _, install := range installList {
|
for _, install := range installList {
|
||||||
if err = syncAppInstallStatus(&install); err != nil {
|
if err = syncAppInstallStatus(&install, false); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
res = append(res, response.WebsitePreInstallCheck{
|
res = append(res, response.WebsitePreInstallCheck{
|
||||||
|
@ -13,7 +13,7 @@ const (
|
|||||||
Syncing = "Syncing"
|
Syncing = "Syncing"
|
||||||
SyncSuccess = "SyncSuccess"
|
SyncSuccess = "SyncSuccess"
|
||||||
Paused = "Paused"
|
Paused = "Paused"
|
||||||
SyncErr = "SyncErr"
|
UpErr = "UpErr"
|
||||||
|
|
||||||
ContainerPrefix = "1Panel-"
|
ContainerPrefix = "1Panel-"
|
||||||
|
|
||||||
|
@ -263,6 +263,7 @@ const message = {
|
|||||||
applying: 'Applying',
|
applying: 'Applying',
|
||||||
applyerror: 'Failure',
|
applyerror: 'Failure',
|
||||||
syncerr: 'Error',
|
syncerr: 'Error',
|
||||||
|
uperr: 'Error',
|
||||||
},
|
},
|
||||||
units: {
|
units: {
|
||||||
second: 'Second',
|
second: 'Second',
|
||||||
|
@ -261,6 +261,7 @@ const message = {
|
|||||||
applying: '申請中',
|
applying: '申請中',
|
||||||
applyerror: '失敗',
|
applyerror: '失敗',
|
||||||
syncerr: '失敗',
|
syncerr: '失敗',
|
||||||
|
uperr: '失败',
|
||||||
},
|
},
|
||||||
units: {
|
units: {
|
||||||
second: '秒',
|
second: '秒',
|
||||||
|
@ -261,6 +261,7 @@ const message = {
|
|||||||
applying: '申请中',
|
applying: '申请中',
|
||||||
applyerror: '失败',
|
applyerror: '失败',
|
||||||
syncerr: '失败',
|
syncerr: '失败',
|
||||||
|
uperr: '失败',
|
||||||
},
|
},
|
||||||
units: {
|
units: {
|
||||||
second: '秒',
|
second: '秒',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user