diff --git a/Mythic_CLI/Changelog.md b/Mythic_CLI/Changelog.md index 9164e784..cfe5ef96 100644 --- a/Mythic_CLI/Changelog.md +++ b/Mythic_CLI/Changelog.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 0.3.9 - 2024-12-18 + +### Changed + +- Updated the container stopping logic to thread instead of doing it sequentially + ## 0.3.8 - 2024-12-10 ### Changed diff --git a/Mythic_CLI/src/cmd/config/vars.go b/Mythic_CLI/src/cmd/config/vars.go index 66cc1aa1..31a75343 100644 --- a/Mythic_CLI/src/cmd/config/vars.go +++ b/Mythic_CLI/src/cmd/config/vars.go @@ -4,5 +4,5 @@ package config var ( // Version Mythic CLI version - Version = "v0.3.8" + Version = "v0.3.9" ) diff --git a/Mythic_CLI/src/cmd/manager/dockerComposeManager.go b/Mythic_CLI/src/cmd/manager/dockerComposeManager.go index 1e8c810e..4eb5d1ad 100644 --- a/Mythic_CLI/src/cmd/manager/dockerComposeManager.go +++ b/Mythic_CLI/src/cmd/manager/dockerComposeManager.go @@ -368,39 +368,52 @@ func (d *DockerComposeManager) StopServices(services []string, deleteImages bool if err != nil { log.Fatalf("Failed to get container list: %v", err) } - for _, service := range services { - found := false - for _, dockerContainer := range allContainers { - if dockerContainer.Labels["name"] == strings.ToLower(service) { - found = true - if deleteImages { - log.Printf("[*] Removing container: %s...\n", service) - err = cli.ContainerRemove(context.Background(), - dockerContainer.ID, - container.RemoveOptions{Force: true, RemoveVolumes: !keepVolume}) - if err != nil { - log.Printf("[-] Failed to remove container: %v\n", err) - return err - } else { - log.Printf("[+] Removed container: %s\n", service) - } - } else { - err = cli.ContainerStop(context.Background(), dockerContainer.ID, container.StopOptions{}) - if err != nil { - log.Printf("[-] Failed to stop container: %v\n", err) - return err + wg := sync.WaitGroup{} + errChan := make(chan error, len(services)) + for _, svc := range services { + wg.Add(1) + go func(service string) { + defer wg.Done() + found := false + for _, dockerContainer := range allContainers { + if dockerContainer.Labels["name"] == strings.ToLower(service) { + found = true + if deleteImages { + log.Printf("[*] Removing container: %s...\n", service) + err = cli.ContainerRemove(context.Background(), + dockerContainer.ID, + container.RemoveOptions{Force: true, RemoveVolumes: !keepVolume}) + if err != nil { + log.Printf("[-] Failed to remove container: %v\n", err) + } else { + log.Printf("[+] Removed container: %s\n", service) + } + errChan <- err } else { - log.Printf("[+] Stopped container: %s\n", service) + err = cli.ContainerStop(context.Background(), dockerContainer.ID, container.StopOptions{}) + if err != nil { + log.Printf("[-] Failed to stop container: %v\n", err) + } else { + log.Printf("[+] Stopped container: %s\n", service) + } + errChan <- err } + break } - } - } - if !found { - log.Printf("[*] Container not running: %s\n", service) + if !found { + log.Printf("[*] Container not running: %s\n", service) + } + }(svc) + } + err = nil + for _, _ = range services { + err2 := <-errChan + if err2 != nil { + err = err2 } } - return nil + return err } // RemoveServices removes certain container entries from the docker-compose