@@ -321,20 +321,17 @@ func StopService(service string) (bool, string) {
321
321
return false , fmt .Sprintf ("Failed to stop service with process id %d" , pid )
322
322
}
323
323
324
- // service takes 30sec time to completely shutdown
325
- success := WaitForServiceDown (service )
324
+ success := WaitForServiceStatus (service , false )
326
325
if ! success {
327
326
StopService (service )
328
327
}
329
328
330
329
delete (runningServices , service )
331
- log .Println (fmt .Sprintf ("oCIS service %s has been stopped successfully" , service ))
332
330
333
331
return true , fmt .Sprintf ("Service %s stopped successfully" , service )
334
332
}
335
333
336
- // wait until the port for a given service is listening
337
- func WaitForService (service string ) bool {
334
+ func WaitForServiceStatus (service string , waitForUp bool ) bool {
338
335
overallTimeout := time .After (30 * time .Second )
339
336
ticker := time .NewTicker (2 * time .Second )
340
337
defer ticker .Stop ()
@@ -344,60 +341,35 @@ func WaitForService(service string) bool {
344
341
for {
345
342
select {
346
343
case <- overallTimeout :
347
- // Timeout occurred while waiting for the service to be available
348
- log .Println (fmt .Errorf ("timeout: %s service did not become available within 30 seconds" , service ).Error ())
349
- return false
350
- case <- ticker .C :
351
- // Retry if the service is not in `runningServices`
352
- if _ , exists := runningServices [service ]; ! exists {
353
- log .Println (fmt .Sprintf ("Service %s not found in running services. Retrying...\n " , service ))
354
- continue
344
+ status := "available"
345
+ if ! waitForUp {
346
+ status = "shut down"
355
347
}
356
-
357
- address := fmt .Sprintf (":%d" , port )
358
- // Try to connect to the port
359
- conn , err := net .DialTimeout ("tcp" , address , 1 * time .Second )
360
- if err == nil {
361
- _ = conn .Close ()
362
- log .Println (fmt .Sprintf ("%s service is ready to listen port %d" , service , port ))
363
- return true
364
- }
365
- log .Println (fmt .Sprintf ("%s service is not ready on port %v. %v\n " , service , port , err ))
366
- }
367
- }
368
- }
369
-
370
- // wwait until service completely down
371
- func WaitForServiceDown (service string ) bool {
372
- overallTimeout := time .After (30 * time .Second )
373
- ticker := time .NewTicker (2 * time .Second )
374
- defer ticker .Stop ()
375
-
376
- port := config .GetServiceDebugPort (service )
377
-
378
- for {
379
- select {
380
- case <- overallTimeout :
381
- // Timeout occurred while waiting for the service to be available
382
- log .Println (fmt .Errorf ("timeout: %s service did not shut down within 30 seconds" , service ).Error ())
348
+ log .Println (fmt .Errorf ("Timeout: %s service did not %s within 30 seconds" , service , status ).Error ())
383
349
return false
384
350
case <- ticker .C :
385
- // Retry if the service is not in `runningServices`
386
351
if _ , exists := runningServices [service ]; ! exists {
387
- log .Println (fmt .Sprintf ("Service %s not found in running services. Retrying...\n " , service ))
352
+ log .Println (fmt .Sprintf ("Service %s not found in running services. Retrying..." , service ))
388
353
continue
389
354
}
390
355
391
356
address := fmt .Sprintf (":%d" , port )
392
- // Try to connect to the port
393
357
conn , err := net .DialTimeout ("tcp" , address , 1 * time .Second )
394
- if err != nil {
395
- log .Println (fmt .Sprintf ("%s service port %d is no longer reachable" , service , port ))
396
- return true
358
+ if waitForUp {
359
+ if err == nil {
360
+ _ = conn .Close ()
361
+ log .Println (fmt .Sprintf ("%s service is ready to listen on port %d" , service , port ))
362
+ return true
363
+ }
364
+ log .Println (fmt .Sprintf ("%s service is not ready on port %d. %v" , service , port , err ))
365
+ } else {
366
+ if err != nil {
367
+ log .Println (fmt .Sprintf ("%s service port %d is no longer reachable" , service , port ))
368
+ return true
369
+ }
370
+ _ = conn .Close ()
371
+ log .Println (fmt .Sprintf ("%s service port %d is still active. Retrying..." , service , port ))
397
372
}
398
- _ = conn .Close ()
399
- log .Println (fmt .Sprintf ("%s service port %d is still active. Retrying..." , service , port ))
400
373
}
401
374
}
402
375
}
403
-
0 commit comments