mirror of
https://github.com/openziti/ziti.git
synced 2026-10-12 15:28:05 +00:00
Add stackdump on SIGQUIT. Add timeout to ziti ps stack
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package subcmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/openziti/edge/edge_common"
|
||||
"github.com/openziti/edge/router/fabric"
|
||||
@@ -26,6 +27,7 @@ import (
|
||||
"github.com/openziti/fabric/router"
|
||||
"github.com/openziti/fabric/router/xgress"
|
||||
"github.com/openziti/foundation/agent"
|
||||
"github.com/openziti/foundation/util/debugz"
|
||||
"github.com/openziti/ziti/common/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -96,7 +98,7 @@ func run(cmd *cobra.Command, args []string) {
|
||||
logrus.Panicf("error registering edge tunnel in framework (%v)", err)
|
||||
}
|
||||
|
||||
go waitForShutdown(r)
|
||||
go waitForShutdown(r, config)
|
||||
|
||||
if err := r.Run(); err != nil {
|
||||
logrus.WithError(err).Fatal("error starting")
|
||||
@@ -115,11 +117,17 @@ func getFlags(cmd *cobra.Command) map[string]*pflag.Flag {
|
||||
return ret
|
||||
}
|
||||
|
||||
func waitForShutdown(r *router.Router) {
|
||||
func waitForShutdown(r *router.Router, config *router.Config) {
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, os.Interrupt, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
|
||||
signal.Notify(ch, os.Interrupt, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
|
||||
|
||||
<-ch
|
||||
s := <-ch
|
||||
|
||||
if s == syscall.SIGQUIT {
|
||||
fmt.Println("=== STACK DUMP BEGIN ===")
|
||||
debugz.DumpStack()
|
||||
fmt.Println("=== STACK DUMP CLOSE ===")
|
||||
}
|
||||
|
||||
pfxlog.Logger().Info("shutting down ziti-router")
|
||||
|
||||
|
||||
@@ -23,12 +23,14 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// PsStackOptions the options for the create spring command
|
||||
type PsStackOptions struct {
|
||||
PsOptions
|
||||
CtrlListener string
|
||||
StackTimeout time.Duration
|
||||
}
|
||||
|
||||
// NewCmdPsStack creates a command object for the "create" command
|
||||
@@ -45,7 +47,7 @@ func NewCmdPsStack(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Use: "stack <optional-target>",
|
||||
Use: "stack [<optional-target>]",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
options.Cmd = cmd
|
||||
options.Args = args
|
||||
@@ -55,12 +57,16 @@ func NewCmdPsStack(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co
|
||||
}
|
||||
|
||||
options.addCommonFlags(cmd)
|
||||
cmd.Flags().DurationVar(&options.StackTimeout, "stack-timeout", 5*time.Second, "Timeout for stack operation")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Run implements the command
|
||||
func (o *PsStackOptions) Run() error {
|
||||
time.AfterFunc(o.StackTimeout, func() {
|
||||
os.Exit(-1)
|
||||
})
|
||||
addr, err := agent.ParseGopsAddress(o.Args)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user