You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ts...@apache.org on 2022/03/09 03:44:54 UTC

[camel-k] branch main updated: fix(cli): make sure kamel local run clean up dirs at ctrl+c

This is an automated email from the ASF dual-hosted git repository.

tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 819dda0  fix(cli): make sure kamel local run clean up dirs at ctrl+c
819dda0 is described below

commit 819dda04fe37f6f3aaaec5772936c11ab8805c4c
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Tue Mar 8 17:26:16 2022 +0900

    fix(cli): make sure kamel local run clean up dirs at ctrl+c
    
    Fix #3029
---
 pkg/cmd/local_run.go             | 16 ++++++++++++++++
 pkg/cmd/util_containerization.go |  6 +++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/pkg/cmd/local_run.go b/pkg/cmd/local_run.go
index a1cf21a..f886dc3 100644
--- a/pkg/cmd/local_run.go
+++ b/pkg/cmd/local_run.go
@@ -19,6 +19,9 @@ package cmd
 
 import (
 	"fmt"
+	"os"
+	"os/signal"
+	"syscall"
 
 	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
@@ -43,6 +46,19 @@ func newCmdLocalRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localRunCm
 			if err := options.init(); err != nil {
 				return err
 			}
+
+			// make sure cleanup is done when process is stopped externally
+			cs := make(chan os.Signal, 1)
+			signal.Notify(cs, os.Interrupt, syscall.SIGTERM)
+			go func() {
+				<-cs
+				if err := options.deinit(); err != nil {
+					fmt.Println(err)
+					os.Exit(1)
+				}
+				os.Exit(0)
+			}()
+
 			if err := options.run(cmd, args); err != nil {
 				fmt.Println(err.Error())
 			}
diff --git a/pkg/cmd/util_containerization.go b/pkg/cmd/util_containerization.go
index aae4f13..c7eac73 100644
--- a/pkg/cmd/util_containerization.go
+++ b/pkg/cmd/util_containerization.go
@@ -95,7 +95,7 @@ func createAndBuildBaseImage(ctx context.Context) error {
 	cmd := exec.CommandContext(ctx, "docker", args...)
 
 	// Output executed command.
-	fmt.Printf("Executing: " + strings.Join(cmd.Args, " ") + "\n")
+	fmt.Printf("Executing: %s\n", strings.Join(cmd.Args, " "))
 
 	// Run the command.
 	if err := cmd.Run(); err != nil {
@@ -192,7 +192,7 @@ func createAndBuildIntegrationImage(ctx context.Context, containerRegistry strin
 	cmd.Stdout = stdout
 
 	// Output executed command.
-	fmt.Printf("Executing: " + strings.Join(cmd.Args, " ") + "\n")
+	fmt.Printf("Executing: %s\n", strings.Join(cmd.Args, " "))
 
 	// Run the command.
 	if err := cmd.Run(); err != nil {
@@ -225,7 +225,7 @@ func runIntegrationImage(ctx context.Context, image string, stdout, stderr io.Wr
 	cmd.Stdout = stdout
 
 	// Output executed command.
-	fmt.Printf("Executing: " + strings.Join(cmd.Args, " ") + "\n")
+	fmt.Printf("Executing: %s\n", strings.Join(cmd.Args, " "))
 
 	// Run the command.
 	if err := cmd.Run(); err != nil {