Skip to content

Commit b3c2e20

Browse files
handle ocis server start in separate routine
1 parent 74de42a commit b3c2e20

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

tests/ociswrapper/ocis/ocis.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ func RunOcisService(service string) {
284284
}
285285

286286
cmd = exec.Command(config.Get("bin"), service, "server")
287+
cmd.Env = append(os.Environ(), EnvConfigs...)
287288

288289
logs, err := cmd.StderrPipe()
289290
if err != nil {
@@ -367,14 +368,12 @@ func StopService(service string) (bool, string) {
367368
return false, fmt.Sprintf("Failed to find process with ID %d", pid)
368369
}
369370

370-
// Send SIGINT to stop the command
371371
err = process.Signal(syscall.SIGINT)
372372
if err != nil {
373373
log.Println(fmt.Sprintf("Failed to send signal: %v", err))
374-
return false, fmt.Sprintf("Failed to stop service with ID %s", service)
374+
return false, fmt.Sprintf("Failed to stop service with PID %d", pid)
375375
}
376376

377-
// Wait for the service to stop
378377
process.Wait()
379378
delete(runningCommands, service)
380379
return true, fmt.Sprintf("Service %s stopped successfully", service)

tests/ociswrapper/wrapper/handlers/handler.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -213,27 +213,31 @@ func OcisServiceHandler(res http.ResponseWriter, req *http.Request) {
213213
serviceName := strings.TrimPrefix(req.URL.Path, "/services/")
214214

215215
if serviceName == "" {
216-
sendResponse(res, http.StatusUnprocessableEntity, "Service name is required")
216+
sendResponse(res, http.StatusUnprocessableEntity, "Service name not specified")
217217
return
218218
}
219+
219220
envVar := fmt.Sprintf("OCIS_EXCLUDE_RUN_SERVICES=%s", serviceName)
220221
ocis.EnvConfigs = append(ocis.EnvConfigs, envVar)
221222

222223
if req.Method == http.MethodPost {
223224
success, _ := ocis.Restart(ocis.EnvConfigs)
224225
if success {
225-
sendResponse(res, http.StatusOK, "oCIS configured successfully")
226-
ocis.RunOcisService(serviceName)
226+
sendResponse(res, http.StatusOK, fmt.Sprintf("oCIS restarted successfully without service %s", serviceName))
227+
228+
go ocis.RunOcisService(serviceName)
229+
230+
sendResponse(res, http.StatusOK, fmt.Sprintf("oCIS service %s started successfully", serviceName))
227231
return
228232
}
229-
sendResponse(res, http.StatusInternalServerError, "Failed to restart oCIS with new configuration")
233+
234+
sendResponse(res, http.StatusInternalServerError, fmt.Sprintf("Failed to restart oCIS without service %s", serviceName))
230235
}
231236

232237
if req.Method == http.MethodDelete {
233-
// Attempt to stop the service
234238
success, message := ocis.StopService(serviceName)
235239
if success {
236-
sendResponse(res, http.StatusOK, fmt.Sprintf("Service %s stopped successfully", serviceName))
240+
sendResponse(res, http.StatusOK, fmt.Sprintf("oCIS service %s stopped successfully", serviceName))
237241
} else {
238242
sendResponse(res, http.StatusInternalServerError, message)
239243
}

0 commit comments

Comments
 (0)