Skip to content

Commit

Permalink
Rename stop-containers to pause, so ddev pause, follow up to #1526 (#…
Browse files Browse the repository at this point in the history
…1537)

* Rename stop-containers to pause, so ddev pause
* Rename app.StopContainers->app.Pause()
  • Loading branch information
rfay committed Apr 23, 2019
1 parent 9388534 commit 44f2c24
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion cmd/ddev/cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var DdevExecCmd = &cobra.Command{
util.Failed("Project is not currently running. Try 'ddev start'.")
}

if strings.Contains(app.SiteStatus(), ddevapp.SiteStopped) {
if strings.Contains(app.SiteStatus(), ddevapp.SitePaused) {
util.Failed("Project is stopped. Run 'ddev start' to start the environment.")
}

Expand Down
42 changes: 42 additions & 0 deletions cmd/ddev/cmd/pause.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"github.com/drud/ddev/pkg/ddevapp"
"github.com/drud/ddev/pkg/util"
"github.com/spf13/cobra"
)

var pauseAllProjects bool

// DdevPauseCommand represents the stop command
var DdevPauseCommand = &cobra.Command{
Use: "pause [projectname ...]",
Short: "uses 'docker stop' to pause/stop the containers belonging to a project.",
Long: `Uses "docker-compose stop" to pause/stop the containers belonging to a project. This leaves the containers instantiated instead of removing them like ddev stop does. You can run 'ddev pause'
from a project directory to stop the containers of that project, or you can stop running projects
in any directory by running 'ddev pause projectname [projectname ...]' or pause all with 'ddev pause --all'`,
Aliases: []string{"sc", "stop-containers"},
Run: func(cmd *cobra.Command, args []string) {
projects, err := getRequestedProjects(args, pauseAllProjects)
if err != nil {
util.Failed("Unable to get project(s): %v", err)
}

for _, project := range projects {
if err := ddevapp.CheckForMissingProjectFiles(project); err != nil {
util.Failed("Failed to pause/stop-containers %s: %v", project.GetName(), err)
}

if err := project.Pause(); err != nil {
util.Failed("Failed to pause/stop-containers %s: %v", project.GetName(), err)
}

util.Success("Project %s has been paused.", project.GetName())
}
},
}

func init() {
DdevPauseCommand.Flags().BoolVarP(&pauseAllProjects, "all", "a", false, "Pause all running projects")
RootCmd.AddCommand(DdevPauseCommand)
}
22 changes: 11 additions & 11 deletions cmd/ddev/cmd/stop-containers_test.go → cmd/ddev/cmd/pause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
asrt "github.com/stretchr/testify/assert"
)

// TestCmdStopContainers runs `ddev stop-containers` on the test apps
func TestCmdStopContainers(t *testing.T) {
// TestCmdPauseContainers runs `ddev pause` on the test apps
func TestCmdPauseContainers(t *testing.T) {
assert := asrt.New(t)

// Make sure we have running sites.
Expand All @@ -27,17 +27,17 @@ func TestCmdStopContainers(t *testing.T) {
for _, site := range DevTestSites {
cleanup := site.Chdir()

out, err := exec.RunCommand(DdevBin, []string{"stop-containers"})
assert.NoError(err, "ddev stop-containers should succeed but failed, err: %v, output: %s", err, out)
assert.Contains(out, "have been stopped")
out, err := exec.RunCommand(DdevBin, []string{"pause"})
assert.NoError(err, "ddev pause should succeed but failed, err: %v, output: %s", err, out)
assert.Contains(out, "has been paused")

apps := ddevapp.GetApps()
for _, app := range apps {
if app.GetName() != site.Name {
continue
}

assert.True(app.SiteStatus() == ddevapp.SiteStopped)
assert.True(app.SiteStatus() == ddevapp.SitePaused)
}

cleanup()
Expand All @@ -46,13 +46,13 @@ func TestCmdStopContainers(t *testing.T) {
// Re-create running sites.
err = addSites()
require.NoError(t, err)
out, err := exec.RunCommand(DdevBin, []string{"stop-containers", "--all"})
assert.NoError(err, "ddev stop --all should succeed but failed, err: %v, output: %s", err, out)
out, err := exec.RunCommand(DdevBin, []string{"pause", "--all"})
assert.NoError(err, "ddev pause --all should succeed but failed, err: %v, output: %s", err, out)

// Confirm all sites are stopped.
apps := ddevapp.GetApps()
for _, app := range apps {
assert.True(app.SiteStatus() == ddevapp.SiteStopped, "All sites should be stopped, but %s status: %s", app.GetName(), app.SiteStatus())
assert.True(app.SiteStatus() == ddevapp.SitePaused, "All sites should be stopped, but %s status: %s", app.GetName(), app.SiteStatus())
}

// Now put the sites back together so other tests can use them.
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestCmdStopContainersMissingProjectDirectory(t *testing.T) {
err = os.Rename(tmpDir, copyDir)
assert.NoError(err)

out, err = exec.RunCommand(DdevBin, []string{"stop-containers", projectName})
assert.Error(err, "Expected an error when stopping project with no project directory")
out, err = exec.RunCommand(DdevBin, []string{"pause", projectName})
assert.Error(err, "Expected an error when pausing project with no project directory")
assert.Contains(out, "ddev can no longer find your project files")
}
2 changes: 1 addition & 1 deletion cmd/ddev/cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var DdevSSHCmd = &cobra.Command{
util.Failed("Project is not currently running. Try 'ddev start'.")
}

if strings.Contains(app.SiteStatus(), ddevapp.SiteStopped) {
if strings.Contains(app.SiteStatus(), ddevapp.SitePaused) {
util.Failed("Project is stopped. Run 'ddev start' to start the environment.")
}

Expand Down
42 changes: 0 additions & 42 deletions cmd/ddev/cmd/stop-containers.go

This file was deleted.

14 changes: 7 additions & 7 deletions pkg/ddevapp/ddevapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const SiteDirMissing = "app directory missing"
// SiteConfigMissing defines the string used to denote when a site is missing its .ddev/config.yml file.
const SiteConfigMissing = ".ddev/config.yaml missing"

// SiteStopped defines the string used to denote when a site is in the stopped state.
const SiteStopped = "stopped"
// SitePaused defines the string used to denote when a site is in the paused (docker stopped) state.
const SitePaused = "paused"

// DdevFileSignature is the text we use to detect whether a settings file is managed by us.
// If this string is found, we assume we can replace/update the file.
Expand Down Expand Up @@ -441,7 +441,7 @@ func (app *DdevApp) SiteStatus() string {

switch status {
case "exited":
statuses[service] = SiteStopped
statuses[service] = SitePaused
case "healthy":
statuses[service] = SiteRunning
case "starting":
Expand Down Expand Up @@ -970,8 +970,8 @@ func (app *DdevApp) DockerEnv() {
}
}

// StopContainers initiates docker-compose stop
func (app *DdevApp) StopContainers() error {
// Pause initiates docker-compose stop
func (app *DdevApp) Pause() error {
app.DockerEnv()

if app.SiteStatus() == SiteNotFound {
Expand Down Expand Up @@ -1146,7 +1146,7 @@ func (app *DdevApp) RestoreSnapshot(snapshotName string) error {
return fmt.Errorf("snapshot %s is a MariaDB %s snapshot\nIt is not compatible with the configured ddev MariaDB version (%s).", snapshotDir, snapshotMariaDBVersion, app.MariaDBVersion)
}

if app.SiteStatus() == SiteRunning || app.SiteStatus() == SiteStopped {
if app.SiteStatus() == SiteRunning || app.SiteStatus() == SitePaused {
err := app.Stop(false, false)
if err != nil {
return fmt.Errorf("Failed to rm project for RestoreSnapshot: %v", err)
Expand Down Expand Up @@ -1180,7 +1180,7 @@ func (app *DdevApp) Stop(removeData bool, createSnapshot bool) error {
}
}

err = app.StopContainers()
err = app.Pause()
if err != nil {
util.Warning("Failed to stop containers for %s: %v", app.GetName(), err)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/ddevapp/ddevapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ func TestDdevLogs(t *testing.T) {
assert.Contains(out, "MySQL init process done. Ready for start up.")

// Test that we can get logs when project is stopped also
err = app.StopContainers()
err = app.Pause()
assert.NoError(err)

stdout = util.CaptureUserOut()
Expand Down Expand Up @@ -1498,7 +1498,7 @@ func TestDdevStop(t *testing.T) {
//nolint: errcheck
defer app.Stop(true, false)
require.NoError(t, err)
err = app.StopContainers()
err = app.Pause()
assert.NoError(err)

for _, containerType := range [3]string{"web", "db", "dba"} {
Expand Down Expand Up @@ -1588,12 +1588,12 @@ func TestDdevDescribe(t *testing.T) {
assert.EqualValues(app.GetPhpVersion(), desc["php_version"])

// Now stop it and test behavior.
err = app.StopContainers()
err = app.Pause()
assert.NoError(err)

desc, err = app.Describe()
assert.NoError(err)
assert.EqualValues(ddevapp.SiteStopped, desc["status"])
assert.EqualValues(ddevapp.SitePaused, desc["status"])

switchDir()
}
Expand Down Expand Up @@ -1644,7 +1644,7 @@ func TestRouterPortsCheck(t *testing.T) {
err := app.Init(site.Dir)
assert.NoError(err)

if app.SiteStatus() == ddevapp.SiteRunning || app.SiteStatus() == ddevapp.SiteStopped {
if app.SiteStatus() == ddevapp.SiteRunning || app.SiteStatus() == ddevapp.SitePaused {
err = app.Stop(true, false)
assert.NoError(err)
}
Expand Down Expand Up @@ -2183,7 +2183,7 @@ func TestInternalAndExternalAccessToURL(t *testing.T) {
err = app.WriteConfig()
assert.NoError(err)

if app.SiteStatus() == ddevapp.SiteStopped || app.SiteStatus() == ddevapp.SiteRunning {
if app.SiteStatus() == ddevapp.SitePaused || app.SiteStatus() == ddevapp.SiteRunning {
err = app.Stop(true, false)
assert.NoError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddevapp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func RenderAppRow(table *uitable.Table, row map[string]interface{}) {
status := fmt.Sprint(row["status"])

switch {
case strings.Contains(status, SiteStopped):
case strings.Contains(status, SitePaused):
status = color.YellowString(status)
case strings.Contains(status, SiteNotFound):
status = color.RedString(status)
Expand Down

0 comments on commit 44f2c24

Please sign in to comment.