-
-
Save jtuchscherer/489fb17445ffd0beea01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"os" | |
"os/exec" | |
"os/signal" | |
"sync" | |
) | |
var cliCount = flag.Int("n", 1, "number of concurrent CLIs") | |
var echoOutput = flag.Bool("e", false, "echo output from CLIs") | |
var appName = flag.String("a", "", "app name to tail logs for") | |
func main() { | |
flag.Parse() | |
killChan := make(chan os.Signal) | |
signal.Notify(killChan, os.Kill, os.Interrupt) | |
stopCommandsChan := make(chan struct{}) | |
go func() { | |
<-killChan | |
close(stopCommandsChan) | |
}() | |
procs := sync.WaitGroup{} | |
counter := *cliCount | |
for i := 0; i < *cliCount; i++ { | |
fmt.Printf("Starting cli #%d\n", i) | |
cmd := exec.Command("cf", "logs", *appName) | |
if *echoOutput { | |
cmd.Stdout = os.Stdout | |
cmd.Stderr = os.Stderr | |
} | |
cmd.Start() | |
go func() { | |
cmd.Wait() | |
counter-- | |
println("###########################################################") | |
fmt.Printf("Lost one connection. Connections left: %d\n", counter) | |
}() | |
go func() { | |
<-stopCommandsChan | |
cmd.Process.Kill() | |
procs.Done() | |
}() | |
procs.Add(1) | |
} | |
procs.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment