github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/pkg/ddevapp/poweroff.go (about)

     1  package ddevapp
     2  
     3  import (
     4  	"github.com/drud/ddev/pkg/dockerutil"
     5  	"github.com/drud/ddev/pkg/util"
     6  	"github.com/drud/ddev/pkg/versionconstants"
     7  	"github.com/fsouza/go-dockerclient"
     8  )
     9  
    10  func PowerOff() {
    11  	apps, err := GetProjects(true)
    12  	if err != nil {
    13  		util.Failed("Failed to get project(s): %v", err)
    14  	}
    15  
    16  	// Remove any custom certs that may have been added
    17  	// along with all traefik configuration.
    18  	_, _, err = dockerutil.RunSimpleContainer(versionconstants.BusyboxImage, "", []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, nil)
    19  	if err != nil {
    20  		util.Warning("Failed removing custom certs/traefik configuration: %v", err)
    21  	}
    22  
    23  	// Iterate through the list of apps built above, stopping each one.
    24  	for _, app := range apps {
    25  		if err := app.Stop(false, false); err != nil {
    26  			util.Failed("Failed to stop project %s: \n%v", app.GetName(), err)
    27  		}
    28  		util.Success("Project %s has been stopped.", app.GetName())
    29  	}
    30  
    31  	StopMutagenDaemon()
    32  
    33  	if err := RemoveSSHAgentContainer(); err != nil {
    34  		util.Error("Failed to remove ddev-ssh-agent: %v", err)
    35  	}
    36  	// Remove current global network ("ddev") plus the former "ddev_default"
    37  	removals := []string{"ddev_default"}
    38  	for _, networkName := range removals {
    39  		err = dockerutil.RemoveNetwork(networkName)
    40  		_, isNoSuchNetwork := err.(*docker.NoSuchNetwork)
    41  		// If it's a "no such network" there's no reason to report error
    42  		if err != nil && !isNoSuchNetwork {
    43  			util.Warning("Unable to remove network %s: %v", "ddev", err)
    44  		}
    45  	}
    46  }