Skip to content

Commit

Permalink
command/debug: capture signals and close the monitor requests
Browse files Browse the repository at this point in the history
  • Loading branch information
langmartin committed Jun 24, 2020
1 parent 9eff486 commit 9746759
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions command/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"io/ioutil"
"net/http"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"

"github.com/hashicorp/nomad/api"
Expand Down Expand Up @@ -206,6 +208,9 @@ func (c *DebugCommand) Run(args []string) int {

c.collectDir = tmp

// Capture signals so we can shutdown the monitor API calls on Int
c.trap()

err = c.collect(client)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error collecting data: %s", err.Error()))
Expand Down Expand Up @@ -403,6 +408,9 @@ func (c *DebugCommand) collectPeriodic(client *api.Client) {
c.collectNomad(dir, client)
interval = time.After(c.interval)
intervalCount += 1

case <-c.stopCh:
return
}
}
}
Expand Down Expand Up @@ -610,6 +618,21 @@ func (c *DebugCommand) writeManifest() error {
return nil
}

// trap captures signals, and closes stopCh
func (c *DebugCommand) trap() {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)

go func() {
<-sigCh
close(c.stopCh)
}()
}

// TarCZF, like the tar command, recursively builds a gzip compressed tar archive from a
// directory
func TarCZF(archive string, src string) error {
Expand Down

0 comments on commit 9746759

Please sign in to comment.