Skip to content

Instantly share code, notes, and snippets.


pims/runner.go Secret

Created Jan 21, 2021
What would you like to do?
package main
import (
func main() {
args := os.Args[1:]
fmt.Println("[runner] starting:", strings.Join(args, ","))
cmd := exec.CommandContext(context.Background(), "envoy", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
var g run.Group
g.Add(func() error {
return cmd.Run()
}, func(err error) {
fmt.Println("[runner] cancelling")
time.Sleep(1 * time.Second)
resp, err = http.Post("http://fly-local-6pn:9901/drain_listeners?graceful", "application/json", nil)
if err != nil {
fmt.Println("[runner] GOT HTTP: ", resp.StatusCode)
fmt.Println("[runner] done drain_listeners?graceful, sleeping 10s")
time.Sleep(10 * time.Second)
if err := syscall.Kill(cmd.Process.Pid, syscall.SIGKILL); err != nil {
fmt.Println("[runner] failed to kill envoy", err)
fmt.Println("[runner] exiting")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
execute, interrupt := run.SignalHandler(ctx, syscall.SIGINT)
g.Add(execute, interrupt)
log.Printf("exit: %v\n", g.Run())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment