-
-
Notifications
You must be signed in to change notification settings - Fork 580
/
restart.go
59 lines (49 loc) · 1.48 KB
/
restart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cmd
import (
"github.com/drud/ddev/pkg/globalconfig"
"strings"
"github.com/drud/ddev/pkg/dockerutil"
"github.com/drud/ddev/pkg/output"
"github.com/drud/ddev/pkg/util"
"github.com/spf13/cobra"
)
var restartAll bool
// RestartCmd rebuilds an apps settings
var RestartCmd = &cobra.Command{
Use: "restart [projects]",
Short: "Restart a project or several projects.",
Long: `Stops named projects and then starts them back up again.`,
Example: `ddev restart
ddev restart <project1> <project2>
ddev restart --all`,
PreRun: func(cmd *cobra.Command, args []string) {
dockerutil.EnsureDdevNetwork()
},
Run: func(cmd *cobra.Command, args []string) {
projects, err := getRequestedProjects(args, restartAll)
if err != nil {
util.Failed("Failed to get project(s): %v", err)
}
for _, app := range projects {
output.UserOut.Printf("Restarting project %s...", app.GetName())
err = app.Stop(false, false)
if err != nil {
util.Failed("Failed to restart %s: %v", app.GetName(), err)
}
err = app.Start()
if err != nil {
util.Failed("Failed to restart %s: %v", app.GetName(), err)
}
util.Success("Restarted %s", app.GetName())
httpURLs, urlList, _ := app.GetAllURLs()
if globalconfig.GetCAROOT() == "" {
urlList = httpURLs
}
util.Success("Your project can be reached at %s", strings.Join(urlList, " "))
}
},
}
func init() {
RestartCmd.Flags().BoolVarP(&restartAll, "all", "a", false, "restart all projects")
RootCmd.AddCommand(RestartCmd)
}