1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-16 18:54:43 +08:00

fix: 解决快照恢复时应用重建无法拉起的问题 (#2287)

This commit is contained in:
ssongliu 2023-09-14 14:06:13 +08:00 committed by GitHub
parent aa057772dc
commit 3bcb5800a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ import (
"github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/cmd"
"github.com/1Panel-dev/1Panel/backend/utils/compose"
"github.com/1Panel-dev/1Panel/backend/utils/docker" "github.com/1Panel-dev/1Panel/backend/utils/docker"
"github.com/1Panel-dev/1Panel/backend/utils/files" "github.com/1Panel-dev/1Panel/backend/utils/files"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
@ -957,14 +958,35 @@ func (u *SnapshotService) handleUnTar(sourceDir, targetDir string) error {
} }
func rebuildAllAppInstall() error { func rebuildAllAppInstall() error {
global.LOG.Debug("start to rebuild all app")
appInstalls, err := appInstallRepo.ListBy() appInstalls, err := appInstallRepo.ListBy()
if err != nil { if err != nil {
global.LOG.Errorf("get all app installed for rebuild failed, err: %v", err) global.LOG.Errorf("get all app installed for rebuild failed, err: %v", err)
return err return err
} }
for _, install := range appInstalls { var wg sync.WaitGroup
_ = rebuildApp(install) for i := 0; i < len(appInstalls); i++ {
wg.Add(1)
appInstalls[i].Status = constant.Rebuilding
_ = appInstallRepo.Save(context.Background(), &appInstalls[i])
go func(app model.AppInstall) {
defer wg.Done()
dockerComposePath := app.GetComposePath()
out, err := compose.Down(dockerComposePath)
if err != nil {
_ = handleErr(app, err, out)
return
}
out, err = compose.Up(dockerComposePath)
if err != nil {
_ = handleErr(app, err, out)
return
}
app.Status = constant.Running
_ = appInstallRepo.Save(context.Background(), &app)
}(appInstalls[i])
} }
wg.Wait()
return nil return nil
} }