github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/ddevapp/poweroff.go (about) 1 package ddevapp 2 3 import ( 4 "github.com/ddev/ddev/pkg/dockerutil" 5 "github.com/ddev/ddev/pkg/util" 6 "github.com/ddev/ddev/pkg/versionconstants" 7 ) 8 9 func PowerOff() { 10 apps, err := GetProjects(true) 11 if err != nil { 12 util.Failed("Failed to get project(s): %v", err) 13 } 14 15 // Remove any custom certs that may have been added 16 // along with all Traefik configuration. 17 _, _, err = dockerutil.RunSimpleContainer(versionconstants.BusyboxImage, "poweroff-"+util.RandString(6), []string{"sh", "-c", "rm -rf /mnt/ddev-global-cache/custom_certs/* /mnt/ddev-global-cache/traefik/*"}, []string{}, []string{}, []string{"ddev-global-cache" + ":/mnt/ddev-global-cache"}, "", true, false, map[string]string{"com.ddev.site-name": ""}, nil, &dockerutil.NoHealthCheck) 18 if err != nil { 19 util.Warning("Failed removing custom certs/traefik configuration: %v", err) 20 } 21 22 // Iterate through the list of apps built above, stopping each one. 23 for _, app := range apps { 24 if err := app.Stop(false, false); err != nil { 25 util.Failed("Failed to stop project %s: \n%v", app.GetName(), err) 26 } 27 util.Success("Project %s has been stopped.", app.GetName()) 28 } 29 30 // Any straggling containers that have label "com.ddev.site-name" should be removed. 31 containers, err := dockerutil.FindContainersByLabels(map[string]string{"com.ddev.site-name": ""}) 32 33 if err == nil { 34 for _, c := range containers { 35 err = dockerutil.RemoveContainer(c.ID) 36 if err != nil { 37 util.Warning("Failed to remove container %s", c.Names[0]) 38 } 39 } 40 } else { 41 util.Warning("Unable to run client.ListContainers(): %v", err) 42 } 43 44 StopMutagenDaemon() 45 46 if err := RemoveSSHAgentContainer(); err != nil { 47 util.Error("Failed to remove ddev-ssh-agent: %v", err) 48 } 49 50 // Remove global DDEV default network 51 dockerutil.RemoveNetworkWithWarningOnError(dockerutil.NetName) 52 53 // Remove all networks created with DDEV 54 removals, err := dockerutil.FindNetworksWithLabel("com.ddev.platform") 55 if err == nil { 56 for _, network := range removals { 57 dockerutil.RemoveNetworkWithWarningOnError(network.Name) 58 } 59 } else { 60 util.Warning("Unable to run dockerutil.FindNetworksWithLabel(): %v", err) 61 } 62 }