-
-
Notifications
You must be signed in to change notification settings - Fork 580
/
restart.go
70 lines (59 loc) · 1.88 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
60
61
62
63
64
65
66
67
68
69
70
package cmd
import (
"strings"
"github.com/ddev/ddev/pkg/ddevapp"
"github.com/ddev/ddev/pkg/dockerutil"
"github.com/ddev/ddev/pkg/output"
"github.com/ddev/ddev/pkg/util"
"github.com/spf13/cobra"
)
var restartAll bool
// RestartCmd rebuilds an apps settings
var RestartCmd = &cobra.Command{
ValidArgsFunction: ddevapp.GetProjectNamesFunc("all", 0),
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(_ *cobra.Command, _ []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)
}
if len(projects) > 0 {
instrumentationApp = projects[0]
}
skip, err := cmd.Flags().GetBool("skip-confirmation")
if err != nil {
util.Failed(err.Error())
}
// Look for version change and opt-in to instrumentation if it has changed.
err = checkDdevVersionAndOptInInstrumentation(skip)
if err != nil {
util.Failed(err.Error())
}
for _, app := range projects {
output.UserOut.Printf("Restarting project %s...", app.GetName())
err = app.Restart()
if err != nil {
util.Failed("Failed to restart %s: %v", app.GetName(), err)
}
util.Success("Restarted %s", app.GetName())
httpURLs, urlList, _ := app.GetAllURLs()
if app.CanUseHTTPOnly() {
urlList = httpURLs
}
util.Success("Your project can be reached at %s", strings.Join(urlList, " "))
}
},
}
func init() {
RestartCmd.Flags().BoolP("skip-confirmation", "y", false, "Skip any confirmation steps")
RestartCmd.Flags().BoolVarP(&restartAll, "all", "a", false, "Restart all projects")
RootCmd.AddCommand(RestartCmd)
}