瀏覽代碼

fmt.Scanln() does not wait forever… waiting for process termination signal

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif 5 年之前
父節點
當前提交
18e43b277c
共有 1 個文件被更改,包括 7 次插入4 次删除
  1. 7 4
      aci/etchosts/main/main.go

+ 7 - 4
aci/etchosts/main/main.go

@@ -18,9 +18,10 @@ package main
 
 import (
 	"fmt"
-	"os"
-
 	"github.com/docker/compose-cli/aci/etchosts"
+	"os"
+	"os/signal"
+	"syscall"
 )
 
 const hosts = "/etc/hosts"
@@ -38,6 +39,8 @@ func main() {
 	}
 
 	// ACI restart policy is currently at container group level, cannot let the sidecar terminate quietly once /etc/hosts has been edited
-	// Pricing is done at the container group level so letting the sidecar container "sleep" should not impact the price for the whole group
-	fmt.Scanln() // pause
+	// Pause forever (until someone explicitely terminates this process ; go is not happy to stop all goroutines otherwise)
+	exitSignal := make(chan os.Signal)
+	signal.Notify(exitSignal, syscall.SIGINT, syscall.SIGTERM)
+	<-exitSignal
 }