Skip to content

Commit

Permalink
Merge pull request #7072 from owncloud/tests/print-err-message
Browse files Browse the repository at this point in the history
[tests-only][ociswrapper] Fix oCIS restart when it exits unexpectedly during startup
  • Loading branch information
kobergj authored Sep 21, 2023
2 parents f0ed33d + d4be6a8 commit 2d3133b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
6 changes: 5 additions & 1 deletion tests/ociswrapper/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ func Println(message string) {
}

func Panic(err error) {
log.Panic("[ociswrapper] ", err.Error())
log.Panic("[ociswrapper]", err.Error())
}

func Fatalln(err error) {
log.Fatalln("[ociswrapper]", err.Error())
}
35 changes: 25 additions & 10 deletions tests/ociswrapper/ocis/ocis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os"
"os/exec"
"strconv"
"strings"
"syscall"
"time"

"ociswrapper/common"
Expand Down Expand Up @@ -58,23 +60,36 @@ func Start(envMap map[string]any) {
for outputScanner.Scan() {
m := outputScanner.Text()
fmt.Println(m)
retryCount++

maxRetry, _ := strconv.Atoi(config.Get("retry"))
if retryCount <= maxRetry {
log.Println(fmt.Sprintf("Retry starting oCIS server... (retry %v)", retryCount))
// Stop and start again
Stop()
Start(envMap)
}

if err := cmd.Wait(); err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
status := exitErr.Sys().(syscall.WaitStatus)
// retry only if oCIS server exited with code > 0
// -1 exit code means that the process was killed by a signal (cmd.Process.Kill())
if status.ExitStatus() > 0 {
log.Println(fmt.Sprintf("oCIS server exited with code %v", status.ExitStatus()))

// retry to start oCIS server
retryCount++
maxRetry, _ := strconv.Atoi(config.Get("retry"))
if retryCount <= maxRetry {
log.Println(fmt.Sprintf("Retry starting oCIS server... (retry %v)", retryCount))
// Stop and start again
Stop()
Start(envMap)
}
}
}
}
cmd.Wait()
}

func Stop() {
err := cmd.Process.Kill()
if err != nil {
log.Panic(err)
if !strings.HasSuffix(err.Error(), "process already finished") {
log.Fatalln(err)
}
}
cmd.Wait()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ociswrapper/wrapper/handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func sendResponse(res http.ResponseWriter, ocisStatus bool) {
} else {
res.WriteHeader(http.StatusInternalServerError)
resBody["status"] = "ERROR"
resBody["message"] = "oCIS server error"
resBody["message"] = "Unable to start oCIS server"
}
res.Header().Set("Content-Type", "application/json")

Expand Down

0 comments on commit 2d3133b

Please sign in to comment.