@@ -803,24 +803,26 @@ public function waitTillContainerStart(string $containerId, DaemonConfig $daemon
803
803
804
804
public function healthcheckContainer (string $ containerId , DaemonConfig $ daemonConfig , bool $ waitForSuccess ): bool {
805
805
$ dockerUrl = $ this ->buildDockerUrl ($ daemonConfig );
806
- $ containerInfo = $ this ->inspectContainer ($ dockerUrl , $ containerId );
807
- if (!isset ($ containerInfo ['State ' ]['Health ' ]['Status ' ])) {
808
- return true ; // container does not support Healthcheck
809
- }
810
- if (!$ waitForSuccess ) {
811
- return $ containerInfo ['State ' ]['Health ' ]['Status ' ] === 'healthy ' ;
812
- }
813
- $ maxTotalAttempts = 900 ;
806
+ $ maxTotalAttempts = $ waitForSuccess ? 900 : 1 ;
814
807
while ($ maxTotalAttempts > 0 ) {
815
808
$ containerInfo = $ this ->inspectContainer ($ dockerUrl , $ containerId );
816
- if ($ containerInfo ['State ' ]['Health ' ]['Status ' ] === 'healthy ' ) {
809
+ if (!isset ($ containerInfo ['State ' ]['Health ' ]['Status ' ])) {
810
+ return true ; // container does not support Healthcheck
811
+ }
812
+ $ status = $ containerInfo ['State ' ]['Health ' ]['Status ' ];
813
+ if ($ status === '' ) {
814
+ return true ; // we treat empty status as 'success', see https://github.com/nextcloud/app_api/issues/439
815
+ }
816
+ if ($ status === 'healthy ' ) {
817
817
return true ;
818
818
}
819
- if ($ containerInfo [ ' State ' ][ ' Health ' ][ ' Status ' ] === 'unhealthy ' ) {
819
+ if ($ status === 'unhealthy ' ) {
820
820
return false ;
821
821
}
822
822
$ maxTotalAttempts --;
823
- sleep (1 );
823
+ if ($ maxTotalAttempts > 0 ) {
824
+ sleep (1 );
825
+ }
824
826
}
825
827
return false ;
826
828
}
0 commit comments