@@ -322,13 +322,13 @@ func StopService(service string) (bool, string) {
322
322
}
323
323
324
324
// service takes 30sec time to completely shutdown
325
- success := WaitForServiceDown (service )
325
+ // success := WaitForServiceDown(service)
326
+ success := WaitForServiceStatus (service , false )
326
327
if ! success {
327
328
StopService (service )
328
329
}
329
330
330
331
delete (runningServices , service )
331
- log .Println (fmt .Sprintf ("oCIS service %s has been stopped successfully" , service ))
332
332
333
333
return true , fmt .Sprintf ("Service %s stopped successfully" , service )
334
334
}
@@ -401,3 +401,45 @@ func WaitForServiceDown(service string) bool {
401
401
}
402
402
}
403
403
404
+ func WaitForServiceStatus (service string , waitForUp bool ) bool {
405
+ overallTimeout := time .After (30 * time .Second )
406
+ ticker := time .NewTicker (2 * time .Second )
407
+ defer ticker .Stop ()
408
+
409
+ port := config .GetServiceDebugPort (service )
410
+
411
+ for {
412
+ select {
413
+ case <- overallTimeout :
414
+ status := "available"
415
+ if ! waitForUp {
416
+ status = "shut down"
417
+ }
418
+ log .Println (fmt .Errorf ("timeout: %s service did not %s within 30 seconds" , service , status ).Error ())
419
+ return false
420
+ case <- ticker .C :
421
+ if _ , exists := runningServices [service ]; ! exists {
422
+ log .Println (fmt .Sprintf ("Service %s not found in running services. Retrying..." , service ))
423
+ continue
424
+ }
425
+
426
+ address := fmt .Sprintf (":%d" , port )
427
+ conn , err := net .DialTimeout ("tcp" , address , 1 * time .Second )
428
+ if waitForUp {
429
+ if err == nil {
430
+ _ = conn .Close ()
431
+ log .Println (fmt .Sprintf ("%s service is ready to listen on port %d" , service , port ))
432
+ return true
433
+ }
434
+ log .Println (fmt .Sprintf ("%s service is not ready on port %d. %v" , service , port , err ))
435
+ } else {
436
+ if err != nil {
437
+ log .Println (fmt .Sprintf ("%s service port %d is no longer reachable" , service , port ))
438
+ return true
439
+ }
440
+ _ = conn .Close ()
441
+ log .Println (fmt .Sprintf ("%s service port %d is still active. Retrying..." , service , port ))
442
+ }
443
+ }
444
+ }
445
+ }
0 commit comments