From bd1c8b2fd86bd9d136b6c39fd2d4b106c02e4169 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Sun, 4 Dec 2022 12:59:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BA=94=E7=94=A8=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20docker-compose=20stop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/app_install.go | 20 ++++++++++++------- backend/utils/compose/compose.go | 2 +- .../src/views/app-store/installed/index.vue | 4 +--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index 07909ad3b..2232b288c 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -376,13 +376,17 @@ func syncById(installId uint) error { errorContainers []string notFoundContainers []string runningContainers []string + exitedContainers []string ) for _, n := range containers { - if n.State != "running" { - errorContainers = append(errorContainers, n.Names[0]) - } else { + switch n.State { + case "exited": + exitedContainers = append(exitedContainers, n.Names[0]) + case "running": runningContainers = append(runningContainers, n.Names[0]) + default: + errorContainers = append(errorContainers, n.Names[0]) } } for _, old := range containerNames { @@ -401,6 +405,7 @@ func syncById(installId uint) error { containerCount := len(containers) errCount := len(errorContainers) notFoundCount := len(notFoundContainers) + existedCount := len(exitedContainers) normalCount := len(containerNames) runningCount := len(runningContainers) @@ -409,16 +414,17 @@ func syncById(installId uint) error { appInstall.Message = "container is not found" return appInstallRepo.Save(&appInstall) } - if errCount == 0 && notFoundCount == 0 { + if errCount == 0 && existedCount == 0 { appInstall.Status = constant.Running return appInstallRepo.Save(&appInstall) } + if existedCount == normalCount { + appInstall.Status = constant.Stopped + return appInstallRepo.Save(&appInstall) + } if errCount == normalCount { appInstall.Status = constant.Error } - if notFoundCount == normalCount { - appInstall.Status = constant.Stopped - } if runningCount < normalCount { appInstall.Status = constant.UnHealthy } diff --git a/backend/utils/compose/compose.go b/backend/utils/compose/compose.go index fbdd234dd..2362db7f2 100644 --- a/backend/utils/compose/compose.go +++ b/backend/utils/compose/compose.go @@ -13,7 +13,7 @@ func Up(filePath string) (string, error) { } func Down(filePath string) (string, error) { - cmd := exec.Command("docker-compose", "-f", filePath, "down") + cmd := exec.Command("docker-compose", "-f", filePath, "stop") stdout, err := cmd.CombinedOutput() return string(stdout), err } diff --git a/frontend/src/views/app-store/installed/index.vue b/frontend/src/views/app-store/installed/index.vue index 624613777..69302e0ff 100644 --- a/frontend/src/views/app-store/installed/index.vue +++ b/frontend/src/views/app-store/installed/index.vue @@ -50,9 +50,7 @@ trigger="hover" :content="row.message" > - +