@@ -223,7 +223,6 @@ func StartService(service string, envMap []string) {
223
223
} else {
224
224
cmd .Env = append (os .Environ (), envMap ... )
225
225
}
226
- log .Println (fmt .Sprintf ("%s" , cmd .Env ))
227
226
228
227
logs , err := cmd .StderrPipe ()
229
228
if err != nil {
@@ -322,6 +321,12 @@ func StopService(service string) (bool, string) {
322
321
return false , fmt .Sprintf ("Failed to stop service with process id %d" , pid )
323
322
}
324
323
324
+ // service takes 30sec time to completely shutdown
325
+ success := WaitForServiceDown (service )
326
+ if ! success {
327
+ StopService (service )
328
+ }
329
+
325
330
delete (runningServices , service )
326
331
log .Println (fmt .Sprintf ("oCIS service %s has been stopped successfully" , service ))
327
332
@@ -361,3 +366,38 @@ func WaitForService(service string) bool {
361
366
}
362
367
}
363
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 ())
383
+ return false
384
+ case <- ticker .C :
385
+ // Retry if the service is not in `runningServices`
386
+ if _ , exists := runningServices [service ]; ! exists {
387
+ log .Println (fmt .Sprintf ("Service %s not found in running services. Retrying...\n " , service ))
388
+ continue
389
+ }
390
+
391
+ address := fmt .Sprintf (":%d" , port )
392
+ // Try to connect to the port
393
+ 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
397
+ }
398
+ _ = conn .Close ()
399
+ log .Println (fmt .Sprintf ("%s service port %d is still active. Retrying..." , service , port ))
400
+ }
401
+ }
402
+ }
403
+
0 commit comments