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
()
| 1183 | // or another status returned from dockerutil.GetContainerHealth(), including |
| 1184 | // "exited", "restarting", "healthy" |
| 1185 | func (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 |
| 1240 | func (app *DdevApp) determineStatus(statuses map[string]string) string { |