From 66c2d8793df19d18902f698003bfb8455ed058ee Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Mon, 22 Dec 2025 07:42:36 +0100 Subject: [PATCH] Fix: process handling of docoer-compose Signed-off-by: Thomas Klaehn --- src/internal/apiservice/printer/printer.go | 16 ++-------- .../app/process/octoprint/octoprint.go | 29 ++++++++++--------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/internal/apiservice/printer/printer.go b/src/internal/apiservice/printer/printer.go index 483aea6..93e10e9 100644 --- a/src/internal/apiservice/printer/printer.go +++ b/src/internal/apiservice/printer/printer.go @@ -112,21 +112,9 @@ func handle_patch_printerstate(w http.ResponseWriter, r *http.Request) { return } if state.State == StateOn { - err = octoprint.ReStart() - if err != nil { - logger.Print(err) - w.WriteHeader(http.StatusInternalServerError) - w.Write(json.RawMessage(fmt.Sprintf(`{"error": "%s"}`, err.Error()))) - return - } + octoprint.ReStart() } else { - err := octoprint.Stop() - if err != nil { - logger.Print(err) - w.WriteHeader(http.StatusInternalServerError) - w.Write(json.RawMessage(fmt.Sprintf(`{"error": "%s"}`, err.Error()))) - return - } + octoprint.Stop() } w.WriteHeader(http.StatusOK) } diff --git a/src/internal/app/process/octoprint/octoprint.go b/src/internal/app/process/octoprint/octoprint.go index 81d69d7..ba2d8bc 100644 --- a/src/internal/app/process/octoprint/octoprint.go +++ b/src/internal/app/process/octoprint/octoprint.go @@ -19,7 +19,7 @@ type DockerState struct { const ( start_cmd = "docker-compose -f /etc/printctrl/octoprint/docker-compose.yml up -d" stop_cmd = "docker-compose -f /etc/printctrl/octoprint/docker-compose.yml down" - status_cmd = "docker ps" + status_cmd = "docker ps -a" ) var ( @@ -30,22 +30,21 @@ func init() { logger.SetFlags(log.Llongfile | log.Ltime) } -func Start() error { +func Start() { p := process.NewProcess(start_cmd) - return p.Start() + p.Start() + p.Wait() } -func Stop() error { +func Stop() { p := process.NewProcess(stop_cmd) - return p.Start() + p.Start() + p.Wait() } -func ReStart() error { - err := Stop() - if err != nil { - logger.Print(err) - } - return Start() +func ReStart() { + Stop() + Start() } func Status() DockerState { @@ -58,7 +57,7 @@ func Status() DockerState { std := <-p.StdoutChannel if strings.Contains(std, "octoprint/octoprint") { res := strings.Split(std, " ") - if len(res) != 7 { + if len(res) < 7 { logger.Printf("Unkown number pf parameters (%d vs. 7)", len(res)) } else { state.ContainerID = res[0] @@ -67,7 +66,11 @@ func Status() DockerState { state.Created = res[3] state.Status = res[4] state.Ports = res[5] - state.Name = res[6] + if len(res) == 7 { + state.Name = res[6] + } else if len(res) == 9 { + state.Name = res[8] + } } } }