mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 08:03:49 +01:00
shutdown hook
This commit is contained in:
parent
cfa603ea0c
commit
ad93c613b5
@ -2,44 +2,63 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/openziti-test-kitchen/zrok/http"
|
"github.com/openziti-test-kitchen/zrok/http"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/rest_client_zrok"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/tunnel"
|
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/tunnel"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var httpCmd = &cobra.Command{
|
var httpCmd = &cobra.Command{
|
||||||
Use: "http <endpoint>",
|
Use: "http <endpoint>",
|
||||||
Short: "Start an http terminator",
|
Short: "Start an http terminator",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: handleHttp,
|
||||||
idCfg, err := zrokdir.IdentityConfigFile()
|
}
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
func handleHttp(_ *cobra.Command, args []string) {
|
||||||
}
|
idCfg, err := zrokdir.IdentityConfigFile()
|
||||||
cfg := &http.Config{
|
if err != nil {
|
||||||
IdentityPath: idCfg,
|
panic(err)
|
||||||
EndpointAddress: args[0],
|
}
|
||||||
}
|
cfg := &http.Config{
|
||||||
id, err := zrokdir.ReadIdentityId()
|
IdentityPath: idCfg,
|
||||||
if err != nil {
|
EndpointAddress: args[0],
|
||||||
panic(err)
|
}
|
||||||
}
|
id, err := zrokdir.ReadIdentityId()
|
||||||
|
if err != nil {
|
||||||
zrok := newZrokClient()
|
panic(err)
|
||||||
req := tunnel.NewTunnelParams()
|
}
|
||||||
req.Body = &rest_model_zrok.TunnelRequest{
|
|
||||||
Endpoint: cfg.EndpointAddress,
|
zrok := newZrokClient()
|
||||||
Identity: id,
|
req := tunnel.NewTunnelParams()
|
||||||
}
|
req.Body = &rest_model_zrok.TunnelRequest{
|
||||||
resp, err := zrok.Tunnel.Tunnel(req)
|
Endpoint: cfg.EndpointAddress,
|
||||||
if err != nil {
|
Identity: id,
|
||||||
panic(err)
|
}
|
||||||
}
|
resp, err := zrok.Tunnel.Tunnel(req)
|
||||||
cfg.Service = resp.Payload.Service
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
if err := http.Run(cfg); err != nil {
|
}
|
||||||
panic(err)
|
cfg.Service = resp.Payload.Service
|
||||||
}
|
|
||||||
},
|
c := make(chan os.Signal)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
<-c
|
||||||
|
cleanupHttp(cfg, zrok)
|
||||||
|
os.Exit(1)
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err := http.Run(cfg); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanupHttp(cfg *http.Config, zrok *rest_client_zrok.Zrok) {
|
||||||
|
logrus.Infof("shutting down '%v'", cfg.Service)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user