@@ -1207,24 +1207,26 @@ public function waitTillContainerStart(string $containerId, DaemonConfig $daemon
12071207
12081208 public function healthcheckContainer (string $ containerId , DaemonConfig $ daemonConfig , bool $ waitForSuccess ): bool {
12091209 $ 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 ;
12181211 while ($ maxTotalAttempts > 0 ) {
12191212 $ 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 ' ) {
12211221 return true ;
12221222 }
1223- if ($ containerInfo [ ' State ' ][ ' Health ' ][ ' Status ' ] === 'unhealthy ' ) {
1223+ if ($ status === 'unhealthy ' ) {
12241224 return false ;
12251225 }
12261226 $ maxTotalAttempts --;
1227- sleep (1 );
1227+ if ($ maxTotalAttempts > 0 ) {
1228+ sleep (1 );
1229+ }
12281230 }
12291231 return false ;
12301232 }
0 commit comments