diff --git a/hossted/utils.go b/hossted/utils.go index 92eaad9..97761b7 100644 --- a/hossted/utils.go +++ b/hossted/utils.go @@ -385,24 +385,37 @@ func PrettyPrint(i interface{}) string { func stopTraefik(appDir string) error { fmt.Println("Stopping traefik...") - command := []string{"sudo docker compose down"} - err, _, stderr := Shell(appDir, command) + // Construct the docker compose down command + cmd := exec.Command("sudo", "docker", "compose", "down") + cmd.Dir = appDir // Set the working directory for the command + + // Run the command and capture stdout and stderr + output, err := cmd.CombinedOutput() if err != nil { - return err + return fmt.Errorf("error stopping traefik: %v\nOutput: %s", err, string(output)) } - fmt.Println(trimOutput(stderr)) - fmt.Println("traefik stopeed") + + // Print the trimmed output for debugging + fmt.Println(string(output)) + fmt.Println("Traefik stopped") return nil } + func dockerUp(appDir string) error { fmt.Println("Restarting service...") - command := []string{"sudo docker compose up -d"} - err, _, stderr := Shell(appDir, command) + // Construct the docker compose command + cmd := exec.Command("sudo", "docker", "compose", "up", "-d") + cmd.Dir = appDir // Set the working directory for the command + + // Run the command and capture stdout and stderr + output, err := cmd.CombinedOutput() if err != nil { - return err + return fmt.Errorf("error running docker compose: %v\nOutput: %s", err, string(output)) } - fmt.Println(trimOutput(stderr)) + + // Print the trimmed output for debugging + fmt.Println(string(output)) return nil } @@ -575,7 +588,7 @@ func sendActivityLog(env, uuid, fullCommand, options, typeActivity string) (acti user, err := user.Current() if err != nil { - log.Fatalf(err.Error()) + log.Fatalf("%s", err.Error()) } userName := user.Username @@ -605,10 +618,10 @@ func sendActivityLog(env, uuid, fullCommand, options, typeActivity string) (acti err = json.Unmarshal([]byte(resp), &response) if err != nil { - return response, fmt.Errorf("Failed to parse JSON. %w", err) + return response, fmt.Errorf("failed to parse JSON. %w", err) } - //fmt.Printf("%v \n", response.Message) + fmt.Printf("calling to activity log api %s\n", response.Message) return response, nil }