Added additional signal handling to catch more terminations for cleanup

This commit is contained in:
Cam Otts 2023-03-31 14:37:15 -05:00
parent 917891e9b1
commit a3ab5521f7
No known key found for this signature in database
GPG Key ID: 367B7C7EBD84A8BD
5 changed files with 28 additions and 24 deletions

View File

@ -1,6 +1,11 @@
package main
import (
"net/url"
"os"
"os/signal"
"syscall"
tea "github.com/charmbracelet/bubbletea"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
@ -13,10 +18,6 @@ import (
"github.com/openziti/zrok/zrokdir"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"net/url"
"os"
"os/signal"
"syscall"
)
func init() {
@ -91,7 +92,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
cfg.RequestsChan = make(chan *endpoints.Request, 1024)
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
go func() {
<-c
cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, shrToken, zrok, auth)

View File

@ -2,6 +2,11 @@ package main
import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
tea "github.com/charmbracelet/bubbletea"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
@ -17,10 +22,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"os"
"os/signal"
"strings"
"syscall"
)
func init() {
@ -129,7 +130,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
}
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
go func() {
<-c
cmd.destroy(zrd.Env.ZId, resp.Payload.ShrToken, zrok, auth)

View File

@ -2,6 +2,11 @@ package main
import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
tea "github.com/charmbracelet/bubbletea"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
@ -17,10 +22,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"os"
"os/signal"
"strings"
"syscall"
)
func init() {
@ -132,7 +133,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
}
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
go func() {
<-c
cmd.destroy(zrd.Env.ZId, resp.Payload.ShrToken, zrok, auth)

View File

@ -4,6 +4,14 @@ import (
"bytes"
"encoding/base64"
"fmt"
"io"
"math/rand"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/openziti/sdk-golang/ziti"
@ -18,13 +26,6 @@ import (
"github.com/openziti/zrok/zrokdir"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"io"
"math/rand"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)
func init() {
@ -76,7 +77,7 @@ func (cmd *testLoopPublicCommand) run(_ *cobra.Command, _ []string) {
go l.run()
}
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
go func() {
<-c
for _, looper := range loopers {

View File

@ -503,5 +503,5 @@ func handleInterrupt(once *sync.Once, s *Server) {
}
func signalNotify(interrupt chan<- os.Signal) {
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
}