Skip to content

Commit

Permalink
updating mythic cli to speed things up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
its-a-feature committed Dec 18, 2024
1 parent 82b67d6 commit d30efca
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
6 changes: 6 additions & 0 deletions Mythic_CLI/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Mythic_CLI/src/cmd/config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package config

var (
// Version Mythic CLI version
Version = "v0.3.8"
Version = "v0.3.9"
)
67 changes: 40 additions & 27 deletions Mythic_CLI/src/cmd/manager/dockerComposeManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d30efca

Please sign in to comment.