@@ -1207,24 +1207,26 @@ public function waitTillContainerStart(string $containerId, DaemonConfig $daemon
1207
1207
1208
1208
public function healthcheckContainer (string $ containerId , DaemonConfig $ daemonConfig , bool $ waitForSuccess ): bool {
1209
1209
$ dockerUrl = $ this ->buildDockerUrl ($ daemonConfig );
1210
- $ containerInfo = $ this ->inspectContainer ($ dockerUrl , $ containerId );
1211
- if (!isset ($ containerInfo ['State ' ]['Health ' ]['Status ' ])) {
1212
- return true ; // container does not support Healthcheck
1213
- }
1214
- if (!$ waitForSuccess ) {
1215
- return $ containerInfo ['State ' ]['Health ' ]['Status ' ] === 'healthy ' ;
1216
- }
1217
- $ maxTotalAttempts = 900 ;
1210
+ $ maxTotalAttempts = $ waitForSuccess ? 900 : 1 ;
1218
1211
while ($ maxTotalAttempts > 0 ) {
1219
1212
$ containerInfo = $ this ->inspectContainer ($ dockerUrl , $ containerId );
1220
- if ($ containerInfo ['State ' ]['Health ' ]['Status ' ] === 'healthy ' ) {
1213
+ if (!isset ($ containerInfo ['State ' ]['Health ' ]['Status ' ])) {
1214
+ return true ; // container does not support Healthcheck
1215
+ }
1216
+ $ status = $ containerInfo ['State ' ]['Health ' ]['Status ' ];
1217
+ if ($ status === '' ) {
1218
+ return true ; // we treat empty status as 'success', see https://github.com/nextcloud/app_api/issues/439
1219
+ }
1220
+ if ($ status === 'healthy ' ) {
1221
1221
return true ;
1222
1222
}
1223
- if ($ containerInfo [ ' State ' ][ ' Health ' ][ ' Status ' ] === 'unhealthy ' ) {
1223
+ if ($ status === 'unhealthy ' ) {
1224
1224
return false ;
1225
1225
}
1226
1226
$ maxTotalAttempts --;
1227
- sleep (1 );
1227
+ if ($ maxTotalAttempts > 0 ) {
1228
+ sleep (1 );
1229
+ }
1228
1230
}
1229
1231
return false ;
1230
1232
}
0 commit comments