Stop stops and Removes the Docker containers for the project in current directory.
(removeData bool, createSnapshot bool)
| 3257 | |
| 3258 | // Stop stops and Removes the Docker containers for the project in current directory. |
| 3259 | func (app *DdevApp) Stop(removeData bool, createSnapshot bool) error { |
| 3260 | _ = app.DockerEnv() |
| 3261 | var err error |
| 3262 | |
| 3263 | clear(EphemeralRouterPortsAssigned) |
| 3264 | if app.Name == "" { |
| 3265 | return fmt.Errorf("invalid app.Name provided to app.Stop(), app=%v", app) |
| 3266 | } |
| 3267 | |
| 3268 | status, _ := app.SiteStatus() |
| 3269 | if status != SiteStopped { |
| 3270 | err = app.ProcessHooks("pre-stop") |
| 3271 | if err != nil { |
| 3272 | return fmt.Errorf("failed to process pre-stop hooks: %v", err) |
| 3273 | } |
| 3274 | } |
| 3275 | |
| 3276 | if createSnapshot { |
| 3277 | if status != SiteRunning { |
| 3278 | util.Warning("Must start non-running project to do database snapshot") |
| 3279 | err = app.Start() |
| 3280 | if err != nil { |
| 3281 | return fmt.Errorf("failed to start project to perform database snapshot") |
| 3282 | } |
| 3283 | } |
| 3284 | t := time.Now() |
| 3285 | _, err = app.Snapshot(app.Name + "_remove_data_snapshot_" + t.Format("20060102150405")) |
| 3286 | if err != nil { |
| 3287 | return err |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | if app.IsMutagenEnabled() { |
| 3292 | err = SyncAndPauseMutagenSession(app) |
| 3293 | if err != nil { |
| 3294 | util.Warning("Unable to SyncAndPauseMutagenSession: %v", err) |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | // Remove the merged traefik config yaml files on stop, but don't delete certs |
| 3299 | // Certs may want to remain for Let's Encrypt, for example, and should do no harm |
| 3300 | // for stopped project |
| 3301 | c := fmt.Sprintf("rm -rf /mnt/ddev-global-cache/traefik/config/%[1]s_merged.yaml", app.Name) |
| 3302 | util.Debug("Removing merged config for project with command '%s'", c) |
| 3303 | _, out, err := dockerutil.RunSimpleContainer(versionconstants.UtilitiesImage, "remove-project-merged-config-"+util.RandString(6), []string{"bash", "-c", c}, []string{}, []string{}, []string{"ddev-global-cache:/mnt/ddev-global-cache"}, "", true, false, map[string]string{`com.ddev.site-name`: ""}, nil, nil) |
| 3304 | if err != nil { |
| 3305 | util.Warning("Unable to remove project merged traefik yaml: %v, output='%s'", err, out) |
| 3306 | } |
| 3307 | |
| 3308 | // If removedata, clean up any data taht was in the ddev-global-cache, including |
| 3309 | // merged traefik config and certs. |
| 3310 | if removeData { |
| 3311 | // If removing data, we want to get rid of the official certs and merged traefik config |
| 3312 | // This would not remove extra certs that they had put in certs directory. |
| 3313 | c := fmt.Sprintf("rm -rf /mnt/ddev-global-cache/*/%[1]s-{web,db} /mnt/ddev-global-cache/traefik/*/%[1]s.{crt,key} /mnt/ddev-global-cache/traefik/config/%[1]s_merged.yaml", app.Name) |
| 3314 | util.Debug("Cleaning ddev-global-cache with command '%s'", c) |
| 3315 | _, out, err := dockerutil.RunSimpleContainer(versionconstants.UtilitiesImage, "clean-ddev-global-cache-"+util.RandString(6), []string{"bash", "-c", c}, []string{}, []string{}, []string{"ddev-global-cache:/mnt/ddev-global-cache"}, "", true, false, map[string]string{`com.ddev.site-name`: ""}, nil, nil) |
| 3316 | if err != nil { |