MCPcopy Index your code
hub / github.com/ddev/ddev / SiteStatus

Method SiteStatus

pkg/ddevapp/ddevapp.go:1185–1237  ·  view source on GitHub ↗

SiteStatus returns the current status of a project determined from web and db service health. returns status, statusDescription Can return SiteConfigMissing, SiteDirMissing, SiteStopped, SiteStarting, SiteRunning, SitePaused, or another status returned from dockerutil.GetContainerHealth(), including

()

Source from the content-addressed store, hash-verified

1183// or another status returned from dockerutil.GetContainerHealth(), including
1184// "exited", "restarting", "healthy"
1185func (app *DdevApp) SiteStatus() (string, string) {
1186 if !fileutil.FileExists(app.GetAppRoot()) {
1187 return SiteDirMissing, fmt.Sprintf(`%s: %v; Please "ddev stop --unlist %s"`, SiteDirMissing, app.GetAppRoot(), app.Name)
1188 }
1189
1190 _, err := CheckForConf(app.GetAppRoot())
1191 if err != nil {
1192 return SiteConfigMissing, SiteConfigMissing
1193 }
1194
1195 statuses := map[string]string{"web": ""}
1196 if !nodeps.ArrayContainsString(app.GetOmittedContainers(), "db") {
1197 statuses["db"] = ""
1198 }
1199
1200 for service := range statuses {
1201 c, err := app.FindContainerByType(service)
1202 if err != nil {
1203 return "", ""
1204 }
1205 if c == nil {
1206 statuses[service] = SiteStopped
1207 } else {
1208 status, _ := dockerutil.GetContainerHealth(c)
1209
1210 switch status {
1211 case "exited":
1212 statuses[service] = SitePaused
1213 case "healthy":
1214 statuses[service] = SiteRunning
1215 case "starting":
1216 statuses[service] = SiteStarting
1217 default:
1218 statuses[service] = status
1219 }
1220 }
1221 }
1222
1223 siteStatusDesc := ""
1224 for serviceName, status := range statuses {
1225 if status != statuses["web"] {
1226 siteStatusDesc += serviceName + ": " + status + "\n"
1227 }
1228 }
1229 siteStatusDesc = strings.TrimSpace(siteStatusDesc)
1230
1231 // Base the siteStatus on web container. Then override it if others are not the same.
1232 if siteStatusDesc == "" {
1233 return app.determineStatus(statuses), statuses["web"]
1234 }
1235
1236 return app.determineStatus(statuses), siteStatusDesc
1237}
1238
1239// Return one of the Site* statuses to describe the overall status of the project
1240func (app *DdevApp) determineStatus(statuses map[string]string) string {

Callers 15

PullMethod · 0.95
PushMethod · 0.95
TestMainFunction · 0.95
TestGetAppsEmptyFunction · 0.95
MutagenSyncFlushMethod · 0.95
RestoreSnapshotMethod · 0.95
CreateSettingsFileMethod · 0.95
DescribeMethod · 0.95
StartOptionalProfilesMethod · 0.95
PauseMethod · 0.95
StopMethod · 0.95
StartAppIfNotRunningMethod · 0.95

Calls 8

GetAppRootMethod · 0.95
GetOmittedContainersMethod · 0.95
FindContainerByTypeMethod · 0.95
determineStatusMethod · 0.95
FileExistsFunction · 0.92
ArrayContainsStringFunction · 0.92
GetContainerHealthFunction · 0.92
CheckForConfFunction · 0.85

Tested by 6

TestMainFunction · 0.76
TestGetAppsEmptyFunction · 0.76
TestCmdMutagenFunction · 0.64
TestCmdStartFunction · 0.64
TestCmdAutostartFunction · 0.64